-
Notifications
You must be signed in to change notification settings - Fork 36
/
linuxkeys.cpp
1039 lines (1006 loc) · 30.8 KB
/
linuxkeys.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
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "linuxkeys.h"
#include "rdkshelljson.h"
#include <iostream>
#include "logger.h"
#include <map>
struct RdkShellKeyMap
{
uint32_t code;
uint32_t flags;
};
static std::map<uint32_t, struct RdkShellKeyMap> sRdkShellKeyMap;
static std::map<std::string, struct RdkShellKeyMap> sRdkShellVirtualKeyMap;
uint32_t getKeyFlag(std::string modifier)
{
uint32_t flag = 0;
if (0 == modifier.compare("ctrl"))
{
flag = RDKSHELL_FLAGS_CONTROL;
}
else if (0 == modifier.compare("shift"))
{
flag = RDKSHELL_FLAGS_SHIFT;
}
else if (0 == modifier.compare("alt"))
{
flag = RDKSHELL_FLAGS_ALT;
}
return flag;
}
void mapNativeKeyCodes()
{
//populate from the key map file
const char* keyMapFile = getenv("RDKSHELL_KEYMAP_FILE");
if (keyMapFile)
{
rapidjson::Document document;
bool ret = RdkShell::RdkShellJson::readJsonFile(keyMapFile, document);
if (false == ret)
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "RDKShell keymap read error : [unable to open/read file (%s)", keyMapFile);
return;
}
if (document.HasMember("keyMappings")) {
const rapidjson::Value& jsonValue = document["keyMappings"];
if (jsonValue.IsArray())
{
for (rapidjson::SizeType k = 0; k < jsonValue.Size(); k++)
{
uint32_t keyCode = 0, mappedKeyCode = 0;
uint32_t flags = 0;
const rapidjson::Value& mapEntry = jsonValue[k];
if (mapEntry.IsObject() && mapEntry.HasMember("keyCode") && mapEntry.HasMember("mapped"))
{
const rapidjson::Value& keyCodeValue = mapEntry["keyCode"];
if (keyCodeValue.IsUint())
{
keyCode = keyCodeValue.GetUint();
}
else
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "Ignoring keycode entry because of format issues of keycode");
continue;
}
const rapidjson::Value& mappedValue = mapEntry["mapped"];
if (mappedValue.IsObject() && mappedValue.HasMember("keyCode") && mappedValue.HasMember("modifiers"))
{
const rapidjson::Value& mappedKeyCodeValue = mappedValue["keyCode"];
if (mappedKeyCodeValue.IsUint())
{
mappedKeyCode = mappedKeyCodeValue.GetUint();
}
else
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "Ignoring keycode entry because of format issues of mapped keycode");
continue;
}
const rapidjson::Value& modifiersValue = mappedValue["modifiers"];
if (modifiersValue.IsArray()) {
for (rapidjson::SizeType i = 0; i < modifiersValue.Size(); i++)
{
if (modifiersValue[i].IsString()) {
flags |= getKeyFlag(modifiersValue[i].GetString());
}
}
}
struct RdkShellKeyMap keyMap;
keyMap.code = mappedKeyCode;
keyMap.flags = flags;
sRdkShellKeyMap[keyCode] = keyMap;
}
else
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "Ignoring keycode entry because of format issues in mapped params");
continue;
}
}
else
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "Ignoring keycode entry because of format issues of keycode entry value");
continue;
}
}
}
}
else
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "Ignored file read due to keyMappings entry not present");
}
}
else
{
RdkShell::Logger::log(RdkShell::LogLevel::Information, "Ignored file read due to keyMap env not set");
}
}
void mapVirtualKeyCodes()
{
//populate from the key map file
const char* virtualKeyMapFile = getenv("RDKSHELL_VIRTUAL_KEYMAP_FILE");
if (virtualKeyMapFile)
{
rapidjson::Document document;
bool ret = RdkShell::RdkShellJson::readJsonFile(virtualKeyMapFile, document);
if (false == ret)
{
std::cout << "RDKShell virtual keymap read error : [unable to open/read file (" << virtualKeyMapFile << ")]\n";
return;
}
if (document.HasMember("virtualKeys"))
{
const rapidjson::Value& jsonValue = document["virtualKeys"];
if (jsonValue.IsArray())
{
for (rapidjson::SizeType k = 0; k < jsonValue.Size(); k++)
{
std::string key;
uint32_t mappedKeyCode = 0;
uint32_t flags = 0;
const rapidjson::Value& mapEntry = jsonValue[k];
if (mapEntry.IsObject() && mapEntry.HasMember("key") && mapEntry.HasMember("keyCode") && mapEntry.HasMember("modifiers"))
{
const rapidjson::Value& keyValue = mapEntry["key"];
if (keyValue.IsString())
{
key = keyValue.GetString();
}
else
{
std::cout << "Ignoring key entry because of format issues of key\n";
continue;
}
const rapidjson::Value& mappedKeyCodeValue = mapEntry["keyCode"];
if (mappedKeyCodeValue.IsUint())
{
mappedKeyCode = mappedKeyCodeValue.GetUint();
}
else
{
std::cout << "Ignoring keycode entry because of format issues of mapped keycode\n";
continue;
}
const rapidjson::Value& modifiersValue = mapEntry["modifiers"];
if (modifiersValue.IsArray()) {
for (rapidjson::SizeType i = 0; i < modifiersValue.Size(); i++)
{
if (modifiersValue[i].IsString()) {
flags |= getKeyFlag(modifiersValue[i].GetString());
}
}
}
struct RdkShellKeyMap keyMap;
keyMap.code = mappedKeyCode;
keyMap.flags = flags;
sRdkShellVirtualKeyMap[key] = keyMap;
}
else
{
std::cout << "Ignoring entry because of missing key/keycode/modifiers params\n";
continue;
}
}
}
else
{
std::cout << "Ignoring keycode entry because of format issues of virtualkeys \n";
}
}
else
{
std::cout << "Ignored file read due to virtualKeys entry not present";
}
}
else
{
std::cout << "Ignored file read due to virtual keyMap env not set\n";
}
}
bool keyCodeFromWayland(uint32_t waylandKeyCode, uint32_t waylandFlags, uint32_t &mappedKeyCode, uint32_t &mappedFlags)
{
RdkShell::Logger::log(RdkShell::LogLevel::Debug, "key event - keyCode: %u flags: %u", waylandKeyCode, waylandFlags);
std::map<uint32_t, struct RdkShellKeyMap>::iterator it = sRdkShellKeyMap.find(waylandKeyCode);
if (it != sRdkShellKeyMap.end())
{
mappedKeyCode = it->second.code;
mappedFlags = it->second.flags;
RdkShell::Logger::log(RdkShell::LogLevel::Debug, "key mapped from config - mappedKeyCode: %u mappedFlags: %u", mappedKeyCode, mappedFlags);
return true;
}
int standardKeyCode = 0;
switch (waylandKeyCode)
{
case WAYLAND_KEY_ENTER:
standardKeyCode = RDKSHELL_KEY_ENTER;
break;
case WAYLAND_KEY_BACKSPACE:
standardKeyCode = RDKSHELL_KEY_BACKSPACE;
break;
case WAYLAND_KEY_TAB:
standardKeyCode = RDKSHELL_KEY_TAB;
break;
case WAYLAND_KEY_RIGHTSHIFT:
standardKeyCode = RDKSHELL_KEY_SHIFT;
break;
case WAYLAND_KEY_LEFTSHIFT:
standardKeyCode = RDKSHELL_KEY_SHIFT;
break;
case WAYLAND_KEY_RIGHTCTRL:
standardKeyCode = RDKSHELL_KEY_CTRL;
break;
case WAYLAND_KEY_LEFTCTRL:
standardKeyCode = RDKSHELL_KEY_CTRL;
break;
case WAYLAND_KEY_RIGHTALT:
standardKeyCode = RDKSHELL_KEY_ALT;
break;
case WAYLAND_KEY_LEFTALT:
standardKeyCode = RDKSHELL_KEY_ALT;
break;
case WAYLAND_KEY_PAUSE:
standardKeyCode = RDKSHELL_KEY_PAUSE;
break;
case WAYLAND_KEY_CAPSLOCK:
standardKeyCode = RDKSHELL_KEY_CAPSLOCK;
break;
case WAYLAND_KEY_ESC:
standardKeyCode = RDKSHELL_KEY_ESCAPE;
break;
case WAYLAND_KEY_SPACE:
standardKeyCode = RDKSHELL_KEY_SPACE;
break;
case WAYLAND_KEY_PAGEUP:
standardKeyCode = RDKSHELL_KEY_PAGEUP;
break;
case WAYLAND_KEY_PAGEDOWN:
standardKeyCode = RDKSHELL_KEY_PAGEDOWN;
break;
case WAYLAND_KEY_END:
standardKeyCode = RDKSHELL_KEY_END;
break;
case WAYLAND_KEY_HOME:
standardKeyCode = RDKSHELL_KEY_HOME;
break;
case WAYLAND_KEY_LEFT:
standardKeyCode = RDKSHELL_KEY_LEFT;
break;
case WAYLAND_KEY_UP:
standardKeyCode = RDKSHELL_KEY_UP;
break;
case WAYLAND_KEY_RIGHT:
standardKeyCode = RDKSHELL_KEY_RIGHT;
break;
case WAYLAND_KEY_DOWN:
standardKeyCode = RDKSHELL_KEY_DOWN;
break;
case WAYLAND_KEY_COMMA:
standardKeyCode = RDKSHELL_KEY_COMMA;
break;
case WAYLAND_KEY_DOT:
standardKeyCode = RDKSHELL_KEY_PERIOD;
break;
case WAYLAND_KEY_SLASH:
standardKeyCode = RDKSHELL_KEY_FORWARDSLASH;
break;
case WAYLAND_KEY_0:
standardKeyCode = RDKSHELL_KEY_ZERO;
break;
case WAYLAND_KEY_1:
standardKeyCode = RDKSHELL_KEY_ONE;
break;
case WAYLAND_KEY_2:
standardKeyCode = RDKSHELL_KEY_TWO;
break;
case WAYLAND_KEY_3:
standardKeyCode = RDKSHELL_KEY_THREE;
break;
case WAYLAND_KEY_4:
standardKeyCode = RDKSHELL_KEY_FOUR;
break;
case WAYLAND_KEY_5:
standardKeyCode = RDKSHELL_KEY_FIVE;
break;
case WAYLAND_KEY_6:
standardKeyCode = RDKSHELL_KEY_SIX;
break;
case WAYLAND_KEY_7:
standardKeyCode = RDKSHELL_KEY_SEVEN;
break;
case WAYLAND_KEY_8:
standardKeyCode = RDKSHELL_KEY_EIGHT;
break;
case WAYLAND_KEY_9:
standardKeyCode = RDKSHELL_KEY_NINE;
break;
case WAYLAND_KEY_SEMICOLON:
standardKeyCode = RDKSHELL_KEY_SEMICOLON;
break;
case WAYLAND_KEY_EQUAL:
standardKeyCode = RDKSHELL_KEY_EQUALS;
break;
case WAYLAND_KEY_A:
standardKeyCode = RDKSHELL_KEY_A;
break;
case WAYLAND_KEY_B:
standardKeyCode = RDKSHELL_KEY_B;
break;
case WAYLAND_KEY_C:
standardKeyCode = RDKSHELL_KEY_C;
break;
case WAYLAND_KEY_D:
standardKeyCode = RDKSHELL_KEY_D;
break;
case WAYLAND_KEY_E:
standardKeyCode = RDKSHELL_KEY_E;
break;
case WAYLAND_KEY_F:
standardKeyCode = RDKSHELL_KEY_F;
break;
case WAYLAND_KEY_G:
standardKeyCode = RDKSHELL_KEY_G;
break;
case WAYLAND_KEY_H:
standardKeyCode = RDKSHELL_KEY_H;
break;
case WAYLAND_KEY_I:
standardKeyCode = RDKSHELL_KEY_I;
break;
case WAYLAND_KEY_J:
standardKeyCode = RDKSHELL_KEY_J;
break;
case WAYLAND_KEY_K:
standardKeyCode = RDKSHELL_KEY_K;
break;
case WAYLAND_KEY_L:
standardKeyCode = RDKSHELL_KEY_L;
break;
case WAYLAND_KEY_M:
standardKeyCode = RDKSHELL_KEY_M;
break;
case WAYLAND_KEY_N:
standardKeyCode = RDKSHELL_KEY_N;
break;
case WAYLAND_KEY_O:
standardKeyCode = RDKSHELL_KEY_O;
break;
case WAYLAND_KEY_P:
standardKeyCode = RDKSHELL_KEY_P;
break;
case WAYLAND_KEY_Q:
standardKeyCode = RDKSHELL_KEY_Q;
break;
case WAYLAND_KEY_R:
standardKeyCode = RDKSHELL_KEY_R;
break;
case WAYLAND_KEY_S:
standardKeyCode = RDKSHELL_KEY_S;
break;
case WAYLAND_KEY_T:
standardKeyCode = RDKSHELL_KEY_T;
break;
case WAYLAND_KEY_U:
standardKeyCode = RDKSHELL_KEY_U;
break;
case WAYLAND_KEY_V:
standardKeyCode = RDKSHELL_KEY_V;
break;
case WAYLAND_KEY_W:
standardKeyCode = RDKSHELL_KEY_W;
break;
case WAYLAND_KEY_X:
standardKeyCode = RDKSHELL_KEY_X;
break;
case WAYLAND_KEY_Y:
standardKeyCode = RDKSHELL_KEY_Y;
break;
case WAYLAND_KEY_Z:
standardKeyCode = RDKSHELL_KEY_Z;
break;
case WAYLAND_KEY_LEFTBRACE:
standardKeyCode = RDKSHELL_KEY_OPENBRACKET;
break;
case WAYLAND_KEY_BACKSLASH:
standardKeyCode = RDKSHELL_KEY_BACKSLASH;
break;
case WAYLAND_KEY_RIGHTBRACE:
standardKeyCode = RDKSHELL_KEY_CLOSEBRACKET;
break;
case WAYLAND_KEY_KP0:
standardKeyCode = RDKSHELL_KEY_NUMPAD0;
break;
case WAYLAND_KEY_KP1:
standardKeyCode = RDKSHELL_KEY_NUMPAD1;
break;
case WAYLAND_KEY_KP2:
standardKeyCode = RDKSHELL_KEY_NUMPAD2;
break;
case WAYLAND_KEY_KP3:
standardKeyCode = RDKSHELL_KEY_NUMPAD3;
break;
case WAYLAND_KEY_KP4:
standardKeyCode = RDKSHELL_KEY_NUMPAD4;
break;
case WAYLAND_KEY_KP5:
standardKeyCode = RDKSHELL_KEY_NUMPAD5;
break;
case WAYLAND_KEY_KP6:
standardKeyCode = RDKSHELL_KEY_NUMPAD6;
break;
case WAYLAND_KEY_KP7:
standardKeyCode = RDKSHELL_KEY_NUMPAD7;
break;
case WAYLAND_KEY_KP8:
standardKeyCode = RDKSHELL_KEY_NUMPAD8;
break;
case WAYLAND_KEY_KP9:
standardKeyCode = RDKSHELL_KEY_NUMPAD9;
break;
case WAYLAND_KEY_KPASTERISK:
standardKeyCode = RDKSHELL_KEY_MULTIPLY;
break;
case WAYLAND_KEY_KPPLUS:
standardKeyCode = RDKSHELL_KEY_ADD;
break;
case WAYLAND_KEY_KPMINUS:
standardKeyCode = RDKSHELL_KEY_SUBTRACT;
break;
case WAYLAND_KEY_KPDOT:
standardKeyCode = RDKSHELL_KEY_DECIMAL;
break;
case WAYLAND_KEY_KPSLASH:
standardKeyCode = RDKSHELL_KEY_DIVIDE;
break;
case WAYLAND_KEY_F1:
standardKeyCode = RDKSHELL_KEY_F1;
break;
case WAYLAND_KEY_F2:
standardKeyCode = RDKSHELL_KEY_F2;
break;
case WAYLAND_KEY_F3:
standardKeyCode = RDKSHELL_KEY_F3;
break;
case WAYLAND_KEY_F4:
standardKeyCode = RDKSHELL_KEY_F4;
break;
case WAYLAND_KEY_F5:
standardKeyCode = RDKSHELL_KEY_F5;
break;
case WAYLAND_KEY_F6:
standardKeyCode = RDKSHELL_KEY_F6;
break;
case WAYLAND_KEY_F7:
standardKeyCode = RDKSHELL_KEY_F7;
break;
case WAYLAND_KEY_F8:
standardKeyCode = RDKSHELL_KEY_F8;
break;
case WAYLAND_KEY_F9:
standardKeyCode = RDKSHELL_KEY_F9;
break;
case WAYLAND_KEY_F10:
standardKeyCode = RDKSHELL_KEY_F10;
break;
case WAYLAND_KEY_F11:
standardKeyCode = RDKSHELL_KEY_F11;
break;
case WAYLAND_KEY_F12:
standardKeyCode = RDKSHELL_KEY_F12;
break;
case WAYLAND_KEY_DELETE:
standardKeyCode = RDKSHELL_KEY_DELETE;
break;
case WAYLAND_KEY_SCROLLLOCK:
standardKeyCode = RDKSHELL_KEY_SCROLLLOCK;
break;
case WAYLAND_KEY_PRINT:
standardKeyCode = RDKSHELL_KEY_PRINTSCREEN;
break;
case WAYLAND_KEY_INSERT:
standardKeyCode = RDKSHELL_KEY_INSERT;
break;
case WAYLAND_KEY_MUTE:
standardKeyCode = RDKSHELL_KEY_MUTE;
break;
case WAYLAND_KEY_VOLUME_DOWN:
standardKeyCode = RDKSHELL_KEY_VOLUME_DOWN;
break;
case WAYLAND_KEY_VOLUME_UP:
standardKeyCode = RDKSHELL_KEY_VOLUME_UP;
break;
#ifdef WAYLAND_KEY_PLAYPAUSE
case WAYLAND_KEY_PLAYPAUSE:
standardKeyCode = RDKSHELL_KEY_PLAYPAUSE;
break;
#endif /* WAYLAND_KEY_PLAYPAUSE */
#ifdef WAYLAND_KEY_PLAY
case WAYLAND_KEY_PLAY:
standardKeyCode = RDKSHELL_KEY_PLAY;
break;
#endif /* WAYLAND_KEY_PLAY */
#ifdef WAYLAND_KEY_FASTFORWARD
case WAYLAND_KEY_FASTFORWARD:
standardKeyCode = RDKSHELL_KEY_FASTFORWARD;
break;
#endif /* RDKSHELL_KEY_FASTFORWARD */
#ifdef WAYLAND_KEY_REWIND
case WAYLAND_KEY_REWIND:
standardKeyCode = RDKSHELL_KEY_REWIND;
break;
#endif /* WAYLAND_KEY_REWIND */
#ifdef WAYLAND_KEY_KPENTER
case WAYLAND_KEY_KPENTER:
standardKeyCode = RDKSHELL_KEY_ENTER;
break;
#endif /* WAYLAND_KEY_KPENTER */
#ifdef WAYLAND_KEY_BACK
case WAYLAND_KEY_BACK:
standardKeyCode = RDKSHELL_KEY_BACK;
break;
#endif /* WAYLAND_KEY_BACK */
#ifdef WAYLAND_KEY_MENU
case WAYLAND_KEY_MENU:
standardKeyCode = RDKSHELL_KEY_MENU;
break;
#endif /* WAYLAND_KEY_MENU */
#ifdef WAYLAND_KEY_HOMEPAGE
case WAYLAND_KEY_HOMEPAGE:
standardKeyCode = RDKSHELL_KEY_HOMEPAGE;
break;
#endif /* WAYLAND_KEY_HOMEPAGE */
case WAYLAND_KEY_F13:
standardKeyCode = RDKSHELL_KEY_F13;
break;
case WAYLAND_KEY_F14:
standardKeyCode = RDKSHELL_KEY_F14;
break;
case WAYLAND_KEY_F15:
standardKeyCode = RDKSHELL_KEY_F15;
break;
case WAYLAND_KEY_F16:
standardKeyCode = RDKSHELL_KEY_F16;
break;
case WAYLAND_KEY_F17:
standardKeyCode = RDKSHELL_KEY_F17;
break;
case WAYLAND_KEY_F18:
standardKeyCode = RDKSHELL_KEY_F18;
break;
case WAYLAND_KEY_F19:
standardKeyCode = RDKSHELL_KEY_F19;
break;
// Key WAYLAND_KEY_F20 is reserved for RDK FP Power key
// case WAYLAND_KEY_F20:
// standardKeyCode = RDKSHELL_KEY_F20;
// break;
case WAYLAND_KEY_F21:
standardKeyCode = RDKSHELL_KEY_F21;
break;
case WAYLAND_KEY_F22:
standardKeyCode = RDKSHELL_KEY_F22;
break;
case WAYLAND_KEY_F23:
standardKeyCode = RDKSHELL_KEY_F23;
break;
case WAYLAND_KEY_F24:
standardKeyCode = RDKSHELL_KEY_F24;
break;
default:
RdkShell::Logger::log(RdkShell::LogLevel::Information, "unknown key code %u", waylandKeyCode);
standardKeyCode = waylandKeyCode;
break;
}
mappedKeyCode = standardKeyCode;
mappedFlags = waylandFlags;
RdkShell::Logger::log(RdkShell::LogLevel::Debug, "key mapped - mappedKeyCode: %u mappedFlags: %u", mappedKeyCode, mappedFlags);
return true;
}
bool keyCodeFromVirtual(std::string& virtualKey, uint32_t &mappedKeyCode, uint32_t &mappedFlags)
{
RdkShell::Logger::log(RdkShell::LogLevel::Debug, "virtual key event - key: %s", virtualKey);
std::map<std::string, struct RdkShellKeyMap>::iterator it = sRdkShellVirtualKeyMap.find(virtualKey);
if (it != sRdkShellVirtualKeyMap.end())
{
mappedKeyCode = it->second.code;
mappedFlags = it->second.flags;
RdkShell::Logger::log(RdkShell::LogLevel::Debug, "virtaul key mapped from config - mappedKeyCode: %u mappedFlags: %u", mappedKeyCode, mappedFlags);
return true;
}
return false;
}
uint32_t keyCodeToWayland(uint32_t keyCode)
{
uint32_t waylandKeyCode = 0;
switch( keyCode )
{
case RDKSHELL_KEY_BACKSPACE:
waylandKeyCode = WAYLAND_KEY_BACKSPACE;
break;
case RDKSHELL_KEY_TAB:
waylandKeyCode = WAYLAND_KEY_TAB;
break;
case RDKSHELL_KEY_ENTER:
waylandKeyCode = WAYLAND_KEY_ENTER;
break;
case RDKSHELL_KEY_SHIFT:
waylandKeyCode = WAYLAND_KEY_LEFTSHIFT;
break;
case RDKSHELL_KEY_CTRL:
waylandKeyCode = WAYLAND_KEY_LEFTCTRL;
break;
case RDKSHELL_KEY_ALT:
waylandKeyCode = WAYLAND_KEY_LEFTALT;
break;
case RDKSHELL_KEY_CAPSLOCK:
waylandKeyCode = WAYLAND_KEY_CAPSLOCK;
break;
case RDKSHELL_KEY_ESCAPE:
waylandKeyCode = WAYLAND_KEY_ESC;
break;
case RDKSHELL_KEY_SPACE:
waylandKeyCode = WAYLAND_KEY_SPACE;
break;
case RDKSHELL_KEY_PAGEUP:
waylandKeyCode = WAYLAND_KEY_PAGEUP;
break;
case RDKSHELL_KEY_PAGEDOWN:
waylandKeyCode = WAYLAND_KEY_PAGEDOWN;
break;
case RDKSHELL_KEY_END:
waylandKeyCode = WAYLAND_KEY_END;
break;
case RDKSHELL_KEY_HOME:
waylandKeyCode = WAYLAND_KEY_HOME;
break;
case RDKSHELL_KEY_LEFT:
waylandKeyCode = WAYLAND_KEY_LEFT;
break;
case RDKSHELL_KEY_UP:
waylandKeyCode = WAYLAND_KEY_UP;
break;
case RDKSHELL_KEY_RIGHT:
waylandKeyCode = WAYLAND_KEY_RIGHT;
break;
case RDKSHELL_KEY_DOWN:
waylandKeyCode = WAYLAND_KEY_DOWN;
break;
case RDKSHELL_KEY_INSERT:
waylandKeyCode = WAYLAND_KEY_INSERT;
break;
case RDKSHELL_KEY_DELETE:
waylandKeyCode = WAYLAND_KEY_DELETE;
break;
case RDKSHELL_KEY_ZERO:
waylandKeyCode = WAYLAND_KEY_0;
break;
case RDKSHELL_KEY_ONE:
waylandKeyCode = WAYLAND_KEY_1;
break;
case RDKSHELL_KEY_TWO:
waylandKeyCode = WAYLAND_KEY_2;
break;
case RDKSHELL_KEY_THREE:
waylandKeyCode = WAYLAND_KEY_3;
break;
case RDKSHELL_KEY_FOUR:
waylandKeyCode = WAYLAND_KEY_4;
break;
case RDKSHELL_KEY_FIVE:
waylandKeyCode = WAYLAND_KEY_5;
break;
case RDKSHELL_KEY_SIX:
waylandKeyCode = WAYLAND_KEY_6;
break;
case RDKSHELL_KEY_SEVEN:
waylandKeyCode = WAYLAND_KEY_7;
break;
case RDKSHELL_KEY_EIGHT:
waylandKeyCode = WAYLAND_KEY_8;
break;
case RDKSHELL_KEY_NINE:
waylandKeyCode = WAYLAND_KEY_9;
break;
case RDKSHELL_KEY_A:
waylandKeyCode = WAYLAND_KEY_A;
break;
case RDKSHELL_KEY_B:
waylandKeyCode = WAYLAND_KEY_B;
break;
case RDKSHELL_KEY_C:
waylandKeyCode = WAYLAND_KEY_C;
break;
case RDKSHELL_KEY_D:
waylandKeyCode = WAYLAND_KEY_D;
break;
case RDKSHELL_KEY_E:
waylandKeyCode = WAYLAND_KEY_E;
break;
case RDKSHELL_KEY_F:
waylandKeyCode = WAYLAND_KEY_F;
break;
case RDKSHELL_KEY_G:
waylandKeyCode = WAYLAND_KEY_G;
break;
case RDKSHELL_KEY_H:
waylandKeyCode = WAYLAND_KEY_H;
break;
case RDKSHELL_KEY_I:
waylandKeyCode = WAYLAND_KEY_I;
break;
case RDKSHELL_KEY_J:
waylandKeyCode = WAYLAND_KEY_J;
break;
case RDKSHELL_KEY_K:
waylandKeyCode = WAYLAND_KEY_K;
break;
case RDKSHELL_KEY_L:
waylandKeyCode = WAYLAND_KEY_L;
break;
case RDKSHELL_KEY_M:
waylandKeyCode = WAYLAND_KEY_M;
break;
case RDKSHELL_KEY_N:
waylandKeyCode = WAYLAND_KEY_N;
break;
case RDKSHELL_KEY_O:
waylandKeyCode = WAYLAND_KEY_O;
break;
case RDKSHELL_KEY_P:
waylandKeyCode = WAYLAND_KEY_P;
break;
case RDKSHELL_KEY_Q:
waylandKeyCode = WAYLAND_KEY_Q;
break;
case RDKSHELL_KEY_R:
waylandKeyCode = WAYLAND_KEY_R;
break;
case RDKSHELL_KEY_S:
waylandKeyCode = WAYLAND_KEY_S;
break;
case RDKSHELL_KEY_T:
waylandKeyCode = WAYLAND_KEY_T;
break;
case RDKSHELL_KEY_U:
waylandKeyCode = WAYLAND_KEY_U;
break;
case RDKSHELL_KEY_V:
waylandKeyCode = WAYLAND_KEY_V;
break;
case RDKSHELL_KEY_W:
waylandKeyCode = WAYLAND_KEY_W;
break;
case RDKSHELL_KEY_X:
waylandKeyCode = WAYLAND_KEY_X;
break;
case RDKSHELL_KEY_Y:
waylandKeyCode = WAYLAND_KEY_Y;
break;
case RDKSHELL_KEY_Z:
waylandKeyCode = WAYLAND_KEY_Z;
break;
case RDKSHELL_KEY_NUMPAD0:
waylandKeyCode = WAYLAND_KEY_KP0;
break;
case RDKSHELL_KEY_NUMPAD1:
waylandKeyCode = WAYLAND_KEY_KP1;
break;
case RDKSHELL_KEY_NUMPAD2:
waylandKeyCode = WAYLAND_KEY_KP2;
break;
case RDKSHELL_KEY_NUMPAD3:
waylandKeyCode = WAYLAND_KEY_KP3;
break;
case RDKSHELL_KEY_NUMPAD4:
waylandKeyCode = WAYLAND_KEY_KP4;
break;
case RDKSHELL_KEY_NUMPAD5:
waylandKeyCode = WAYLAND_KEY_KP5;
break;
case RDKSHELL_KEY_NUMPAD6:
waylandKeyCode = WAYLAND_KEY_KP6;
break;
case RDKSHELL_KEY_NUMPAD7:
waylandKeyCode = WAYLAND_KEY_KP7;
break;
case RDKSHELL_KEY_NUMPAD8:
waylandKeyCode = WAYLAND_KEY_KP8;
break;
case RDKSHELL_KEY_NUMPAD9:
waylandKeyCode = WAYLAND_KEY_KP9;
break;
case RDKSHELL_KEY_MULTIPLY:
waylandKeyCode = WAYLAND_KEY_KPASTERISK;
break;
case RDKSHELL_KEY_ADD:
waylandKeyCode = WAYLAND_KEY_KPPLUS;
break;
case RDKSHELL_KEY_SUBTRACT:
waylandKeyCode = WAYLAND_KEY_KPMINUS;
break;
case RDKSHELL_KEY_DECIMAL:
waylandKeyCode = WAYLAND_KEY_KPDOT;
break;
case RDKSHELL_KEY_DIVIDE:
waylandKeyCode = WAYLAND_KEY_KPSLASH;
break;
case RDKSHELL_KEY_F1:
waylandKeyCode = WAYLAND_KEY_F1;
break;
case RDKSHELL_KEY_F2:
waylandKeyCode = WAYLAND_KEY_F2;
break;
case RDKSHELL_KEY_F3:
waylandKeyCode = WAYLAND_KEY_F3;
break;
case RDKSHELL_KEY_F4:
waylandKeyCode = WAYLAND_KEY_F4;
break;
case RDKSHELL_KEY_F5:
waylandKeyCode = WAYLAND_KEY_F5;
break;
case RDKSHELL_KEY_F6:
waylandKeyCode = WAYLAND_KEY_F6;
break;
case RDKSHELL_KEY_F7:
waylandKeyCode = WAYLAND_KEY_F7;
break;
case RDKSHELL_KEY_F8:
waylandKeyCode = WAYLAND_KEY_F8;
break;
case RDKSHELL_KEY_F9:
waylandKeyCode = WAYLAND_KEY_F9;
break;
case RDKSHELL_KEY_F10:
waylandKeyCode = WAYLAND_KEY_F10;
break;
case RDKSHELL_KEY_F11:
waylandKeyCode = WAYLAND_KEY_F11;
break;
case RDKSHELL_KEY_F12:
waylandKeyCode = WAYLAND_KEY_F12;
break;
case RDKSHELL_KEY_NUMLOCK:
waylandKeyCode = WAYLAND_KEY_NUMLOCK;
break;
case RDKSHELL_KEY_SCROLLLOCK:
waylandKeyCode = WAYLAND_KEY_SCROLLLOCK;
break;
case RDKSHELL_KEY_SEMICOLON:
waylandKeyCode = WAYLAND_KEY_SEMICOLON;
break;
case RDKSHELL_KEY_EQUALS:
waylandKeyCode = WAYLAND_KEY_EQUAL;
break;
case RDKSHELL_KEY_COMMA:
waylandKeyCode = WAYLAND_KEY_COMMA;
break;
case RDKSHELL_KEY_PERIOD:
waylandKeyCode = WAYLAND_KEY_DOT;
break;
case RDKSHELL_KEY_FORWARDSLASH:
waylandKeyCode = WAYLAND_KEY_SLASH;
break;
case RDKSHELL_KEY_GRAVEACCENT:
waylandKeyCode = WAYLAND_KEY_GRAVE;
break;
case RDKSHELL_KEY_OPENBRACKET:
waylandKeyCode = WAYLAND_KEY_LEFTBRACE;
break;
case RDKSHELL_KEY_BACKSLASH:
waylandKeyCode = WAYLAND_KEY_BACKSLASH;
break;
case RDKSHELL_KEY_CLOSEBRACKET:
waylandKeyCode = WAYLAND_KEY_RIGHTBRACE;
break;
case RDKSHELL_KEY_SINGLEQUOTE:
waylandKeyCode = WAYLAND_KEY_APOSTROPHE;
break;
case RDKSHELL_KEY_PRINTSCREEN:
waylandKeyCode = WAYLAND_KEY_PRINT;
break;
case RDKSHELL_KEY_DASH:
waylandKeyCode = WAYLAND_KEY_MINUS;
break;
case RDKSHELL_KEY_FASTFORWARD:
waylandKeyCode = WAYLAND_KEY_FASTFORWARD;
break;
case RDKSHELL_KEY_REWIND:
waylandKeyCode = WAYLAND_KEY_REWIND;
break;
case RDKSHELL_KEY_PAUSE:
waylandKeyCode = WAYLAND_KEY_PAUSE;
break;
case RDKSHELL_KEY_PLAY:
waylandKeyCode = WAYLAND_KEY_PLAY;
break;
case RDKSHELL_KEY_PLAYPAUSE:
waylandKeyCode = WAYLAND_KEY_PLAYPAUSE;
break;
case RDKSHELL_KEY_YELLOW:
waylandKeyCode = WAYLAND_KEY_YELLOW;
break;
case RDKSHELL_KEY_BLUE:
waylandKeyCode = WAYLAND_KEY_BLUE;
break;
case RDKSHELL_KEY_RED:
waylandKeyCode = WAYLAND_KEY_RED;
break;
case RDKSHELL_KEY_GREEN:
waylandKeyCode = WAYLAND_KEY_GREEN;
break;
case RDKSHELL_KEY_BACK:
waylandKeyCode = WAYLAND_KEY_BACK;
break;
case RDKSHELL_KEY_MENU:
waylandKeyCode = WAYLAND_KEY_MENU;
break;
case RDKSHELL_KEY_HOMEPAGE:
waylandKeyCode = WAYLAND_KEY_HOMEPAGE;
break;
case RDKSHELL_KEY_MUTE:
waylandKeyCode = WAYLAND_KEY_MUTE;
break;
case RDKSHELL_KEY_VOLUME_DOWN:
waylandKeyCode = WAYLAND_KEY_VOLUME_DOWN;
break;
case RDKSHELL_KEY_VOLUME_UP:
waylandKeyCode = WAYLAND_KEY_VOLUME_UP;
break;
case RDKSHELL_KEY_F13:
waylandKeyCode = WAYLAND_KEY_F13;
break;
case RDKSHELL_KEY_F14:
waylandKeyCode = WAYLAND_KEY_F14;