forked from EmuELEC/gptokeyb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gptokeyb.cpp
2473 lines (2304 loc) · 96.5 KB
/
gptokeyb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2021
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
#
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
#
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
#
* Authored by: Kris Henriksen <krishenriksen.work@gmail.com>
#
* AnberPorts-Keyboard-Mouse
*
* Part of the code is from from https://github.com/krishenriksen/AnberPorts/blob/master/AnberPorts-Keyboard-Mouse/main.c (mostly the fake keyboard)
* Fake Xbox code from: https://github.com/Emanem/js2xbox
*
* Modified (badly) by: Shanti Gilbert for EmuELEC
* Modified further by: Nikolai Wuttke for EmuELEC (Added support for SDL and the SDLGameControllerdb.txt)
*
* Any help improving this code would be greatly appreciated!
*
* DONE: Xbox360 mode: Fix triggers so that they report from 0 to 255 like real Xbox triggers
* Xbox360 mode: Figure out why the axis are not correctly labeled? SDL_CONTROLLER_AXIS_RIGHTX / SDL_CONTROLLER_AXIS_RIGHTY / SDL_CONTROLLER_AXIS_TRIGGERLEFT / SDL_CONTROLLER_AXIS_TRIGGERRIGHT
* Keyboard mode: Add a config file option to load mappings from.
* add L2/R2 triggers
*
* Spaghetti code incoming, beware :)
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include <libevdev-1.0/libevdev/libevdev-uinput.h>
#include <libevdev-1.0/libevdev/libevdev.h>
#include <fcntl.h>
#include <sstream>
#include <string.h>
#include <unistd.h>
#include <vector>
#include <SDL.h>
#define CONFIG_ARG_MAX_BYTES 128
#define SDL_DEFAULT_REPEAT_DELAY 500
#define SDL_DEFAULT_REPEAT_INTERVAL 30
struct config_option
{
char key[CONFIG_ARG_MAX_BYTES];
char value[CONFIG_ARG_MAX_BYTES];
};
std::vector<config_option> parseConfigFile(const char* path)
{
std::vector<config_option> result;
FILE* fp;
if ((fp = fopen(path, "r+")) == NULL) {
perror("fopen()");
return result;
}
while (1) {
result.emplace_back();
auto& co = result.back();
if (fscanf(fp, "%s = %s", &co.key[0], &co.value[0]) != 2) {
if (feof(fp)) {
break;
}
if (co.key[0] == '#') {
while (fgetc(fp) != '\n') {
// Do nothing (to move the cursor to the end of the line).
}
result.pop_back();
continue;
}
perror("fscanf()");
result.pop_back();
continue;
}
}
return result;
}
static int uinp_fd = -1;
struct uinput_user_dev uidev;
bool kill_mode = false;
bool sudo_kill = false; //allow sudo kill instead of killall for non-emuelec systems
bool pckill_mode = false; //emit alt+f4 to close apps on pc during kill mode, if env variable is set
bool openbor_mode = false;
bool xbox360_mode = false;
bool textinputpreset_mode = false;
bool textinputinteractive_mode = false;
bool textinputinteractive_noautocapitals = false;
bool textinputinteractive_extrasymbols = false;
bool app_exult_adjust = false;
const int maxKeysNoExtendedSymbols = 69; //number of keys available for interactive text input
const int maxKeysWithSymbols = 96; //number of keys available for interactive text input with extra symbols
int maxKeys = maxKeysNoExtendedSymbols;
const int maxChars = 20; // length of text in characters that can be entered
int character_set[maxKeysWithSymbols]; // keys that can be selected in text input interactive mode
bool character_set_shift[maxKeysWithSymbols]; // indicate which keys require shift
int current_character = 0;
int current_key[maxChars]; // current key selected for each key
char* AppToKill;
bool config_mode = false;
bool hotkey_override = false;
bool emuelec_override = false;
char* hotkey_code;
struct
{
int hotkey_jsdevice;
int start_jsdevice;
int textinputinteractivetrigger_jsdevice; // to trigger text input interactive
int textinputpresettrigger_jsdevice; // to trigger text input preset
int textinputconfirmtrigger_jsdevice; // to trigger text input confirm via Enter key
int mouseX = 0;
int mouseY = 0;
int current_left_analog_x = 0;
int current_left_analog_y = 0;
int current_right_analog_x = 0;
int current_right_analog_y = 0;
int current_l2 = 0;
int current_r2 = 0;
bool hotkey_pressed = false; // current state of hotkey
bool hotkey_was_pressed = false; // indicates hotkey button has been pressed, and key may need to be processed on button's release, if hotkey combo isn't triggered
bool start_pressed = false;
bool start_was_pressed = false; // indicates start button has been pressed, and key may need to be processed on button's release, if start combo isn't triggered
bool textinputinteractive_mode_active = false;
bool textinputinteractivetrigger_pressed = false;
bool textinputpresettrigger_pressed = false;
bool textinputconfirmtrigger_pressed = false;
bool left_analog_was_up = false;
bool left_analog_was_down = false;
bool left_analog_was_left = false;
bool left_analog_was_right = false;
bool right_analog_was_up = false;
bool right_analog_was_down = false;
bool right_analog_was_left = false;
bool right_analog_was_right = false;
bool a_hk_was_pressed = false;
bool b_hk_was_pressed = false;
bool x_hk_was_pressed = false;
bool y_hk_was_pressed = false;
bool l1_hk_was_pressed = false;
bool r1_hk_was_pressed = false;
bool l2_was_pressed = false;
bool l2_hk_was_pressed = false;
bool r2_was_pressed = false;
bool r2_hk_was_pressed = false;
bool hotkey_combo_triggered = false; //keep track of whether a hotkey combo was pressed; if so, don't send hotkey key when hotkey is released
bool start_combo_triggered = false; //keep track of whether a start combo was pressed; if so, don't send start key when start is released
short key_to_repeat = 0;
SDL_TimerID key_repeat_timer_id = 0;
} state;
struct
{
short back = KEY_ESC;
bool back_repeat = false;
short back_modifier = 0;
short start = KEY_ENTER;
bool start_repeat = false;
short start_modifier = 0;
short guide = KEY_ENTER;
bool guide_repeat = false;
short guide_modifier = 0;
short a = KEY_X;
short a_hk = KEY_ENTER;
bool a_repeat = false;
short a_modifier = 0;
short a_hk_modifier = 0;
short b = KEY_Z;
short b_hk = KEY_ESC;
bool b_repeat = false;
short b_modifier = 0;
short b_hk_modifier = 0;
short x = KEY_C;
short x_hk = KEY_C;
bool x_repeat = false;
short x_modifier = 0;
short x_hk_modifier = 0;
short y = KEY_A;
short y_hk = KEY_A;
bool y_repeat = false;
short y_modifier = 0;
short y_hk_modifier = 0;
short l1 = KEY_RIGHTSHIFT;
short l1_hk = KEY_ESC;
bool l1_repeat = false;
short l1_modifier = 0;
short l1_hk_modifier = 0;
short l2 = KEY_HOME;
short l2_hk = KEY_HOME;
bool l2_repeat = false;
short l2_modifier = 0;
short l2_hk_modifier = 0;
short l3 = BTN_LEFT;
bool l3_repeat = false;
short l3_modifier = 0;
short r1 = KEY_LEFTSHIFT;
short r1_hk = KEY_ENTER;
bool r1_repeat = false;
short r1_modifier = 0;
short r1_hk_modifier = 0;
short r2 = KEY_END;
short r2_hk = KEY_END;
bool r2_repeat = false;
short r2_modifier = 0;
short r2_hk_modifier = 0;
short r3 = BTN_RIGHT;
bool r3_repeat = false;
short r3_modifier = 0;
short up = KEY_UP;
bool up_repeat = false;
short up_modifier = 0;
short down = KEY_DOWN;
bool down_repeat = false;
short down_modifier = 0;
short left = KEY_LEFT;
bool left_repeat = false;
short left_modifier = 0;
short right = KEY_RIGHT;
bool right_repeat = false;
short right_modifier = 0;
bool left_analog_as_mouse = false;
bool right_analog_as_mouse = false;
short left_analog_up = KEY_W;
bool left_analog_up_repeat = false;
short left_analog_up_modifier = 0;
short left_analog_down = KEY_S;
bool left_analog_down_repeat = false;
short left_analog_down_modifier = 0;
short left_analog_left = KEY_A;
bool left_analog_left_repeat = false;
short left_analog_left_modifier = 0;
short left_analog_right = KEY_D;
bool left_analog_right_repeat = false;
short left_analog_right_modifier = 0;
short right_analog_up = KEY_END;
bool right_analog_up_repeat = false;
short right_analog_up_modifier = 0;
short right_analog_down = KEY_HOME;
bool right_analog_down_repeat = false;
short right_analog_down_modifier = 0;
short right_analog_left = KEY_LEFT;
bool right_analog_left_repeat = false;
short right_analog_left_modifier = 0;
short right_analog_right = KEY_RIGHT;
bool right_analog_right_repeat = false;
short right_analog_right_modifier = 0;
int deadzone_y = 15000;
int deadzone_x = 15000;
int deadzone_triggers = 3000;
int fake_mouse_scale = 512;
int fake_mouse_delay = 16;
Uint32 key_repeat_interval = SDL_DEFAULT_REPEAT_INTERVAL * 2;
Uint32 key_repeat_delay = SDL_DEFAULT_REPEAT_DELAY;
char* text_input_preset;
} config;
// convert ASCII chars to key codes
short char_to_keycode(const char* str)
{
short keycode;
// arrow keys
if (strcmp(str, "up") == 0)
keycode = KEY_UP;
else if (strcmp(str, "down") == 0)
keycode = KEY_DOWN;
else if (strcmp(str, "left") == 0)
keycode = KEY_LEFT;
else if (strcmp(str, "right") == 0)
keycode = KEY_RIGHT;
// special keys
else if (strcmp(str, "mouse_left") == 0)
keycode = BTN_LEFT;
else if (strcmp(str, "mouse_right") == 0)
keycode = BTN_RIGHT;
else if (strcmp(str, "space") == 0)
keycode = KEY_SPACE;
else if (strcmp(str, "esc") == 0)
keycode = KEY_ESC;
else if (strcmp(str, "end") == 0)
keycode = KEY_END;
else if (strcmp(str, "home") == 0)
keycode = KEY_HOME;
else if (strcmp(str, "shift") == 0)
keycode = KEY_LEFTSHIFT;
else if (strcmp(str, "leftshift") == 0)
keycode = KEY_LEFTSHIFT;
else if (strcmp(str, "rightshift") == 0)
keycode = KEY_RIGHTSHIFT;
else if (strcmp(str, "ctrl") == 0)
keycode = KEY_LEFTCTRL;
else if (strcmp(str, "leftctrl") == 0)
keycode = KEY_LEFTCTRL;
else if (strcmp(str, "rightctrl") == 0)
keycode = KEY_RIGHTCTRL;
else if (strcmp(str, "alt") == 0)
keycode = KEY_LEFTALT;
else if (strcmp(str, "leftalt") == 0)
keycode = KEY_LEFTALT;
else if (strcmp(str, "rightalt") == 0)
keycode = KEY_RIGHTALT;
else if (strcmp(str, "backspace") == 0)
keycode = KEY_BACKSPACE;
else if (strcmp(str, "enter") == 0)
keycode = KEY_ENTER;
else if (strcmp(str, "pageup") == 0)
keycode = KEY_PAGEUP;
else if (strcmp(str, "pagedown") == 0)
keycode = KEY_PAGEDOWN;
else if (strcmp(str, "insert") == 0)
keycode = KEY_INSERT;
else if (strcmp(str, "delete") == 0)
keycode = KEY_DELETE;
else if (strcmp(str, "capslock") == 0)
keycode = KEY_CAPSLOCK;
else if (strcmp(str, "tab") == 0)
keycode = KEY_TAB;
else if (strcmp(str, "pause") == 0)
keycode = KEY_PAUSE;
else if (strcmp(str, "menu") == 0)
keycode = KEY_MENU;
// normal keyboard
else if (strcmp(str, "a") == 0)
keycode = KEY_A;
else if (strcmp(str, "b") == 0)
keycode = KEY_B;
else if (strcmp(str, "c") == 0)
keycode = KEY_C;
else if (strcmp(str, "d") == 0)
keycode = KEY_D;
else if (strcmp(str, "e") == 0)
keycode = KEY_E;
else if (strcmp(str, "f") == 0)
keycode = KEY_F;
else if (strcmp(str, "g") == 0)
keycode = KEY_G;
else if (strcmp(str, "h") == 0)
keycode = KEY_H;
else if (strcmp(str, "i") == 0)
keycode = KEY_I;
else if (strcmp(str, "j") == 0)
keycode = KEY_J;
else if (strcmp(str, "k") == 0)
keycode = KEY_K;
else if (strcmp(str, "l") == 0)
keycode = KEY_L;
else if (strcmp(str, "m") == 0)
keycode = KEY_M;
else if (strcmp(str, "n") == 0)
keycode = KEY_N;
else if (strcmp(str, "o") == 0)
keycode = KEY_O;
else if (strcmp(str, "p") == 0)
keycode = KEY_P;
else if (strcmp(str, "q") == 0)
keycode = KEY_Q;
else if (strcmp(str, "r") == 0)
keycode = KEY_R;
else if (strcmp(str, "s") == 0)
keycode = KEY_S;
else if (strcmp(str, "t") == 0)
keycode = KEY_T;
else if (strcmp(str, "u") == 0)
keycode = KEY_U;
else if (strcmp(str, "v") == 0)
keycode = KEY_V;
else if (strcmp(str, "w") == 0)
keycode = KEY_W;
else if (strcmp(str, "x") == 0)
keycode = KEY_X;
else if (strcmp(str, "y") == 0)
keycode = KEY_Y;
else if (strcmp(str, "z") == 0)
keycode = KEY_Z;
else if (strcmp(str, "1") == 0)
keycode = KEY_1;
else if (strcmp(str, "2") == 0)
keycode = KEY_2;
else if (strcmp(str, "3") == 0)
keycode = KEY_3;
else if (strcmp(str, "4") == 0)
keycode = KEY_4;
else if (strcmp(str, "5") == 0)
keycode = KEY_5;
else if (strcmp(str, "6") == 0)
keycode = KEY_6;
else if (strcmp(str, "7") == 0)
keycode = KEY_7;
else if (strcmp(str, "8") == 0)
keycode = KEY_8;
else if (strcmp(str, "9") == 0)
keycode = KEY_9;
else if (strcmp(str, "0") == 0)
keycode = KEY_0;
else if (strcmp(str, "f1") == 0)
keycode = KEY_F1;
else if (strcmp(str, "f2") == 0)
keycode = KEY_F2;
else if (strcmp(str, "f3") == 0)
keycode = KEY_F3;
else if (strcmp(str, "f4") == 0)
keycode = KEY_F4;
else if (strcmp(str, "f5") == 0)
keycode = KEY_F5;
else if (strcmp(str, "f6") == 0)
keycode = KEY_F6;
else if (strcmp(str, "f7") == 0)
keycode = KEY_F7;
else if (strcmp(str, "f8") == 0)
keycode = KEY_F8;
else if (strcmp(str, "f9") == 0)
keycode = KEY_F9;
else if (strcmp(str, "f10") == 0)
keycode = KEY_F10;
else if (strcmp(str, "@") == 0)
keycode = KEY_2; // with SHIFT
else if (strcmp(str, "#") == 0)
keycode = KEY_3; // with SHIFT
//else if (strcmp(str, "€") == 0) keycode = KEY_5; // with ALTGR; not ASCII
else if (strcmp(str, "%") == 0)
keycode = KEY_5; // with SHIFT
else if (strcmp(str, "&") == 0)
keycode = KEY_7; // with SHIFT
else if (strcmp(str, "*") == 0)
keycode = KEY_8; // with SHIFT; alternative is KEY_KPASTERISK
else if (strcmp(str, "-") == 0)
keycode = KEY_MINUS; // alternative is KEY_KPMINUS
else if (strcmp(str, "+") == 0)
keycode = KEY_EQUAL; // with SHIFT; alternative is KEY_KPPLUS
else if (strcmp(str, "(") == 0)
keycode = KEY_9; // with SHIFT
else if (strcmp(str, ")") == 0)
keycode = KEY_0; // with SHIFT
else if (strcmp(str, "!") == 0)
keycode = KEY_1; // with SHIFT
else if (strcmp(str, "\"") == 0)
keycode = KEY_APOSTROPHE; // with SHIFT, dead key
else if (strcmp(str, "\'") == 0)
keycode = KEY_APOSTROPHE; // dead key
else if (strcmp(str, ":") == 0)
keycode = KEY_SEMICOLON; // with SHIFT
else if (strcmp(str, ";") == 0)
keycode = KEY_SEMICOLON;
else if (strcmp(str, "/") == 0)
keycode = KEY_SLASH;
else if (strcmp(str, "?") == 0)
keycode = KEY_SLASH; // with SHIFT
else if (strcmp(str, ".") == 0)
keycode = KEY_DOT;
else if (strcmp(str, ",") == 0)
keycode = KEY_COMMA;
// special chars
else if (strcmp(str, "~") == 0)
keycode = KEY_GRAVE; // with SHIFT, dead key
else if (strcmp(str, "`") == 0)
keycode = KEY_GRAVE; // dead key
else if (strcmp(str, "|") == 0)
keycode = KEY_BACKSLASH; // with SHIFT
else if (strcmp(str, "{") == 0)
keycode = KEY_LEFTBRACE; // with SHIFT
else if (strcmp(str, "}") == 0)
keycode = KEY_RIGHTBRACE; // with SHIFT
else if (strcmp(str, "$") == 0)
keycode = KEY_4; // with SHIFT
else if (strcmp(str, "^") == 0)
keycode = KEY_6; // with SHIFT, dead key
else if (strcmp(str, "_") == 0)
keycode = KEY_MINUS; // with SHIFT
else if (strcmp(str, "=") == 0)
keycode = KEY_EQUAL;
else if (strcmp(str, "[") == 0)
keycode = KEY_LEFTBRACE;
else if (strcmp(str, "]") == 0)
keycode = KEY_RIGHTBRACE;
else if (strcmp(str, "\\") == 0)
keycode = KEY_BACKSLASH;
else if (strcmp(str, "<") == 0)
keycode = KEY_COMMA; // with SHIFT
else if (strcmp(str, ">") == 0)
keycode = KEY_DOT; // with SHIFT
return keycode;
}
void initialiseCharacters()
{
if (textinputinteractive_noautocapitals) {
current_key[0] = 26; // if environment variable has been set to disable capitalisation of first characters start with all lower case
} else {
current_key[0] = 0; // otherwise start with upper case for 1st character
}
for (int ii = 1; ii < maxChars; ii++) { // start with lower case for other character onwards
current_key[ii] = 26;
}
}
void initialiseCharacterSet()
{
character_set[0]=char_to_keycode("a"); //capital letters
character_set_shift[0]=true;
character_set[1]=char_to_keycode("b");
character_set_shift[1]=true;
character_set[2]=char_to_keycode("c");
character_set_shift[2]=true;
character_set[3]=char_to_keycode("d");
character_set_shift[3]=true;
character_set[4]=char_to_keycode("e");
character_set_shift[4]=true;
character_set[5]=char_to_keycode("f");
character_set_shift[5]=true;
character_set[6]=char_to_keycode("g");
character_set_shift[6]=true;
character_set[7]=char_to_keycode("h");
character_set_shift[7]=true;
character_set[8]=char_to_keycode("i");
character_set_shift[8]=true;
character_set[9]=char_to_keycode("j");
character_set_shift[9]=true;
character_set[10]=char_to_keycode("k");
character_set_shift[10]=true;
character_set[11]=char_to_keycode("l");
character_set_shift[11]=true;
character_set[12]=char_to_keycode("m");
character_set_shift[12]=true;
character_set[13]=char_to_keycode("n");
character_set_shift[13]=true;
character_set[14]=char_to_keycode("o");
character_set_shift[14]=true;
character_set[15]=char_to_keycode("p");
character_set_shift[15]=true;
character_set[16]=char_to_keycode("q");
character_set_shift[16]=true;
character_set[17]=char_to_keycode("r");
character_set_shift[17]=true;
character_set[18]=char_to_keycode("s");
character_set_shift[18]=true;
character_set[19]=char_to_keycode("t");
character_set_shift[19]=true;
character_set[20]=char_to_keycode("u");
character_set_shift[20]=true;
character_set[21]=char_to_keycode("v");
character_set_shift[21]=true;
character_set[22]=char_to_keycode("w");
character_set_shift[22]=true;
character_set[23]=char_to_keycode("x");
character_set_shift[23]=true;
character_set[24]=char_to_keycode("y");
character_set_shift[24]=true;
character_set[25]=char_to_keycode("z");
character_set_shift[25]=true;
character_set[26]=char_to_keycode("a"); //lower case
character_set_shift[26]=false;
character_set[27]=char_to_keycode("b");
character_set_shift[27]=false;
character_set[28]=char_to_keycode("c");
character_set_shift[28]=false;
character_set[29]=char_to_keycode("d");
character_set_shift[29]=false;
character_set[30]=char_to_keycode("e");
character_set_shift[30]=false;
character_set[31]=char_to_keycode("f");
character_set_shift[31]=false;
character_set[32]=char_to_keycode("g");
character_set_shift[32]=false;
character_set[33]=char_to_keycode("h");
character_set_shift[33]=false;
character_set[34]=char_to_keycode("i");
character_set_shift[34]=false;
character_set[35]=char_to_keycode("j");
character_set_shift[35]=false;
character_set[36]=char_to_keycode("k");
character_set_shift[36]=false;
character_set[37]=char_to_keycode("l");
character_set_shift[37]=false;
character_set[38]=char_to_keycode("m");
character_set_shift[38]=false;
character_set[39]=char_to_keycode("n");
character_set_shift[39]=false;
character_set[40]=char_to_keycode("o");
character_set_shift[40]=false;
character_set[41]=char_to_keycode("p");
character_set_shift[41]=false;
character_set[42]=char_to_keycode("q");
character_set_shift[42]=false;
character_set[43]=char_to_keycode("r");
character_set_shift[43]=false;
character_set[44]=char_to_keycode("s");
character_set_shift[44]=false;
character_set[45]=char_to_keycode("t");
character_set_shift[45]=false;
character_set[46]=char_to_keycode("u");
character_set_shift[46]=false;
character_set[47]=char_to_keycode("v");
character_set_shift[47]=false;
character_set[48]=char_to_keycode("w");
character_set_shift[48]=false;
character_set[49]=char_to_keycode("x");
character_set_shift[49]=false;
character_set[50]=char_to_keycode("y");
character_set_shift[50]=false;
character_set[51]=char_to_keycode("z");
character_set_shift[51]=false;
character_set[52]=char_to_keycode("0");
character_set_shift[52]=false;
character_set[53]=char_to_keycode("1");
character_set_shift[53]=false;
character_set[54]=char_to_keycode("2");
character_set_shift[54]=false;
character_set[55]=char_to_keycode("3");
character_set_shift[55]=false;
character_set[56]=char_to_keycode("4");
character_set_shift[56]=false;
character_set[57]=char_to_keycode("5");
character_set_shift[57]=false;
character_set[58]=char_to_keycode("6");
character_set_shift[58]=false;
character_set[59]=char_to_keycode("7");
character_set_shift[59]=false;
character_set[60]=char_to_keycode("8");
character_set_shift[60]=false;
character_set[61]=char_to_keycode("9");
character_set_shift[61]=false;
character_set[62]=char_to_keycode("space");
character_set_shift[62]=false;
character_set[63]=char_to_keycode(".");
character_set_shift[63]=false;
character_set[64]=char_to_keycode(",");
character_set_shift[64]=false;
character_set[65]=char_to_keycode("-");
character_set_shift[65]=false;
character_set[66]=char_to_keycode("_");
character_set_shift[66]=true;
character_set[67]=char_to_keycode("(");
character_set_shift[67]=true;
character_set[68]=char_to_keycode(")");
character_set_shift[68]=true;
if (textinputinteractive_extrasymbols) {
maxKeys = maxKeysWithSymbols;
character_set[69]=char_to_keycode("@");
character_set_shift[69]=true;
character_set[70]=char_to_keycode("#");
character_set_shift[70]=true;
character_set[71]=char_to_keycode("%");
character_set_shift[71]=true;
character_set[72]=char_to_keycode("&");
character_set_shift[72]=true;
character_set[73]=char_to_keycode("*");
character_set_shift[73]=true;
character_set[74]=char_to_keycode("-");
character_set_shift[74]=false;
character_set[75]=char_to_keycode("+");
character_set_shift[75]=true;
character_set[76]=char_to_keycode("!");
character_set_shift[76]=true;
character_set[77]=char_to_keycode("\"");
character_set_shift[77]=true;
character_set[78]=char_to_keycode("\'");
character_set_shift[78]=false;
character_set[79]=char_to_keycode(":");
character_set_shift[79]=true;
character_set[80]=char_to_keycode(";");
character_set_shift[80]=false;
character_set[81]=char_to_keycode("/");
character_set_shift[81]=false;
character_set[82]=char_to_keycode("?");
character_set_shift[82]=true;
character_set[83]=char_to_keycode("~");
character_set_shift[83]=true;
character_set[84]=char_to_keycode("`");
character_set_shift[84]=false;
character_set[85]=char_to_keycode("|");
character_set_shift[85]=true;
character_set[86]=char_to_keycode("{");
character_set_shift[86]=true;
character_set[87]=char_to_keycode("}");
character_set_shift[87]=true;
character_set[88]=char_to_keycode("$");
character_set_shift[88]=true;
character_set[89]=char_to_keycode("^");
character_set_shift[89]=true;
character_set[90]=char_to_keycode("=");
character_set_shift[90]=false;
character_set[91]=char_to_keycode("[");
character_set_shift[91]=false;
character_set[92]=char_to_keycode("]");
character_set_shift[92]=false;
character_set[93]=char_to_keycode("\\");
character_set_shift[93]=false;
character_set[94]=char_to_keycode("<");
character_set_shift[94]=true;
character_set[95]=char_to_keycode(">");
character_set_shift[95]=true;
}
initialiseCharacters();
}
void readConfigFile(const char* config_file)
{
const auto parsedConfig = parseConfigFile(config_file);
for (const auto& co : parsedConfig) {
if (strcmp(co.key, "back") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.back_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.back_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.back_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.back_modifier = KEY_LEFTSHIFT;
} else {
config.back = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "guide") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.guide_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.guide_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.guide_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.guide_modifier = KEY_LEFTSHIFT;
} else {
config.guide = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "start") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.start_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.start_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.start_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.start_modifier = KEY_LEFTSHIFT;
} else {
config.start = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "a") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.a_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.a_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.a_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.a_modifier = KEY_LEFTSHIFT;
} else {
config.a = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "a_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.a_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.a_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.a_hk_modifier = KEY_LEFTSHIFT;
} else {
config.a_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "b") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.b_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.b_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.b_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.b_modifier = KEY_LEFTSHIFT;
} else {
config.b = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "b_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.b_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.b_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.b_hk_modifier = KEY_LEFTSHIFT;
} else {
config.b_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "x") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.x_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.x_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.x_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.x_modifier = KEY_LEFTSHIFT;
} else {
config.x = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "x_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.x_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.x_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.x_hk_modifier = KEY_LEFTSHIFT;
} else {
config.x_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "y") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.y_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.y_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.y_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.y_modifier = KEY_LEFTSHIFT;
} else {
config.y = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "y_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.y_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.y_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.y_hk_modifier = KEY_LEFTSHIFT;
} else {
config.y_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "l1") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.l1_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.l1_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.l1_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.l1_modifier = KEY_LEFTSHIFT;
} else {
config.l1 = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "l1_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.l1_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.l1_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.l1_hk_modifier = KEY_LEFTSHIFT;
} else {
config.l1_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "l2") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.l2_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.l2_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.l2_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.l2_modifier = KEY_LEFTSHIFT;
} else {
config.l2 = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "l2_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.l2_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.l2_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.l2_hk_modifier = KEY_LEFTSHIFT;
} else {
config.l2_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "l3") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.l3_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.l3_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.l3_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.l3_modifier = KEY_LEFTSHIFT;
} else {
config.l3 = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "r1") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.r1_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.r1_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.r1_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.r1_modifier = KEY_LEFTSHIFT;
} else {
config.r1 = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "r1_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.r1_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.r1_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.r1_hk_modifier = KEY_LEFTSHIFT;
} else {
config.r1_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "r2") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.r2_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.r2_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.r2_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.r2_modifier = KEY_LEFTSHIFT;
} else {
config.r2 = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "r2_hk") == 0) {
if (strcmp(co.value, "add_alt") == 0) {
config.r2_hk_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.r2_hk_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.r2_hk_modifier = KEY_LEFTSHIFT;
} else {
config.r2_hk = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "r3") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.r3_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.r3_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.r3_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.r3_modifier = KEY_LEFTSHIFT;
} else {
config.r3 = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "up") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.up_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.up_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.up_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.up_modifier = KEY_LEFTSHIFT;
} else {
config.up = char_to_keycode(co.value);
}
} else if (strcmp(co.key, "down") == 0) {
if (strcmp(co.value, "repeat") == 0) {
config.down_repeat = true;
} else if (strcmp(co.value, "add_alt") == 0) {
config.down_modifier = KEY_LEFTALT;
} else if (strcmp(co.value, "add_ctrl") == 0) {
config.down_modifier = KEY_LEFTCTRL;
} else if (strcmp(co.value, "add_shift") == 0) {
config.down_modifier = KEY_LEFTSHIFT;
} else {
config.down = char_to_keycode(co.value);
}