]> git.proxmox.com Git - mirror_novnc.git/blob - core/input/domkeytable.js
Merge branch 'fix/ie11-numpad5-compatibility' of https://github.com/vlastoun/noVNC
[mirror_novnc.git] / core / input / domkeytable.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2017 Pierre Ossman for Cendio AB
4 * Licensed under MPL 2.0 or any later version (see LICENSE.txt)
5 */
6
7 import KeyTable from "./keysym.js";
8
9 /*
10 * Mapping between HTML key values and VNC/X11 keysyms for "special"
11 * keys that cannot be handled via their Unicode codepoint.
12 *
13 * See https://www.w3.org/TR/uievents-key/ for possible values.
14 */
15
16 const DOMKeyTable = {};
17
18 function addStandard(key, standard)
19 {
20 if (standard === undefined) throw "Undefined keysym for key \"" + key + "\"";
21 if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
22 DOMKeyTable[key] = [standard, standard, standard, standard];
23 }
24
25 function addLeftRight(key, left, right)
26 {
27 if (left === undefined) throw "Undefined keysym for key \"" + key + "\"";
28 if (right === undefined) throw "Undefined keysym for key \"" + key + "\"";
29 if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
30 DOMKeyTable[key] = [left, left, right, left];
31 }
32
33 function addNumpad(key, standard, numpad)
34 {
35 if (standard === undefined) throw "Undefined keysym for key \"" + key + "\"";
36 if (numpad === undefined) throw "Undefined keysym for key \"" + key + "\"";
37 if (key in DOMKeyTable) throw "Duplicate entry for key \"" + key + "\"";
38 DOMKeyTable[key] = [standard, standard, standard, numpad];
39 }
40
41 // 2.2. Modifier Keys
42
43 addLeftRight("Alt", KeyTable.XK_Alt_L, KeyTable.XK_Alt_R);
44 addStandard("AltGraph", KeyTable.XK_ISO_Level3_Shift);
45 addStandard("CapsLock", KeyTable.XK_Caps_Lock);
46 addLeftRight("Control", KeyTable.XK_Control_L, KeyTable.XK_Control_R);
47 // - Fn
48 // - FnLock
49 addLeftRight("Hyper", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
50 addLeftRight("Meta", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
51 addStandard("NumLock", KeyTable.XK_Num_Lock);
52 addStandard("ScrollLock", KeyTable.XK_Scroll_Lock);
53 addLeftRight("Shift", KeyTable.XK_Shift_L, KeyTable.XK_Shift_R);
54 addLeftRight("Super", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
55 // - Symbol
56 // - SymbolLock
57
58 // 2.3. Whitespace Keys
59
60 addNumpad("Enter", KeyTable.XK_Return, KeyTable.XK_KP_Enter);
61 addStandard("Tab", KeyTable.XK_Tab);
62 addNumpad(" ", KeyTable.XK_space, KeyTable.XK_KP_Space);
63
64 // 2.4. Navigation Keys
65
66 addNumpad("ArrowDown", KeyTable.XK_Down, KeyTable.XK_KP_Down);
67 addNumpad("ArrowUp", KeyTable.XK_Up, KeyTable.XK_KP_Up);
68 addNumpad("ArrowLeft", KeyTable.XK_Left, KeyTable.XK_KP_Left);
69 addNumpad("ArrowRight", KeyTable.XK_Right, KeyTable.XK_KP_Right);
70 addNumpad("End", KeyTable.XK_End, KeyTable.XK_KP_End);
71 addNumpad("Home", KeyTable.XK_Home, KeyTable.XK_KP_Home);
72 addNumpad("PageDown", KeyTable.XK_Next, KeyTable.XK_KP_Next);
73 addNumpad("PageUp", KeyTable.XK_Prior, KeyTable.XK_KP_Prior);
74
75 // 2.5. Editing Keys
76
77 addStandard("Backspace", KeyTable.XK_BackSpace);
78 addNumpad("Clear", KeyTable.XK_Clear, KeyTable.XK_KP_Begin);
79 addStandard("Copy", KeyTable.XF86XK_Copy);
80 // - CrSel
81 addStandard("Cut", KeyTable.XF86XK_Cut);
82 addNumpad("Delete", KeyTable.XK_Delete, KeyTable.XK_KP_Delete);
83 // - EraseEof
84 // - ExSel
85 addNumpad("Insert", KeyTable.XK_Insert, KeyTable.XK_KP_Insert);
86 addStandard("Paste", KeyTable.XF86XK_Paste);
87 addStandard("Redo", KeyTable.XK_Redo);
88 addStandard("Undo", KeyTable.XK_Undo);
89
90 // 2.6. UI Keys
91
92 // - Accept
93 // - Again (could just be XK_Redo)
94 // - Attn
95 addStandard("Cancel", KeyTable.XK_Cancel);
96 addStandard("ContextMenu", KeyTable.XK_Menu);
97 addStandard("Escape", KeyTable.XK_Escape);
98 addStandard("Execute", KeyTable.XK_Execute);
99 addStandard("Find", KeyTable.XK_Find);
100 addStandard("Help", KeyTable.XK_Help);
101 addStandard("Pause", KeyTable.XK_Pause);
102 // - Play
103 // - Props
104 addStandard("Select", KeyTable.XK_Select);
105 addStandard("ZoomIn", KeyTable.XF86XK_ZoomIn);
106 addStandard("ZoomOut", KeyTable.XF86XK_ZoomOut);
107
108 // 2.7. Device Keys
109
110 addStandard("BrightnessDown", KeyTable.XF86XK_MonBrightnessDown);
111 addStandard("BrightnessUp", KeyTable.XF86XK_MonBrightnessUp);
112 addStandard("Eject", KeyTable.XF86XK_Eject);
113 addStandard("LogOff", KeyTable.XF86XK_LogOff);
114 addStandard("Power", KeyTable.XF86XK_PowerOff);
115 addStandard("PowerOff", KeyTable.XF86XK_PowerDown);
116 addStandard("PrintScreen", KeyTable.XK_Print);
117 addStandard("Hibernate", KeyTable.XF86XK_Hibernate);
118 addStandard("Standby", KeyTable.XF86XK_Standby);
119 addStandard("WakeUp", KeyTable.XF86XK_WakeUp);
120
121 // 2.8. IME and Composition Keys
122
123 addStandard("AllCandidates", KeyTable.XK_MultipleCandidate);
124 addStandard("Alphanumeric", KeyTable.XK_Eisu_Shift); // could also be _Eisu_Toggle
125 addStandard("CodeInput", KeyTable.XK_Codeinput);
126 addStandard("Compose", KeyTable.XK_Multi_key);
127 addStandard("Convert", KeyTable.XK_Henkan);
128 // - Dead
129 // - FinalMode
130 addStandard("GroupFirst", KeyTable.XK_ISO_First_Group);
131 addStandard("GroupLast", KeyTable.XK_ISO_Last_Group);
132 addStandard("GroupNext", KeyTable.XK_ISO_Next_Group);
133 addStandard("GroupPrevious", KeyTable.XK_ISO_Prev_Group);
134 // - ModeChange (XK_Mode_switch is often used for AltGr)
135 // - NextCandidate
136 addStandard("NonConvert", KeyTable.XK_Muhenkan);
137 addStandard("PreviousCandidate", KeyTable.XK_PreviousCandidate);
138 // - Process
139 addStandard("SingleCandidate", KeyTable.XK_SingleCandidate);
140 addStandard("HangulMode", KeyTable.XK_Hangul);
141 addStandard("HanjaMode", KeyTable.XK_Hangul_Hanja);
142 addStandard("JunjuaMode", KeyTable.XK_Hangul_Jeonja);
143 addStandard("Eisu", KeyTable.XK_Eisu_toggle);
144 addStandard("Hankaku", KeyTable.XK_Hankaku);
145 addStandard("Hiragana", KeyTable.XK_Hiragana);
146 addStandard("HiraganaKatakana", KeyTable.XK_Hiragana_Katakana);
147 addStandard("KanaMode", KeyTable.XK_Kana_Shift); // could also be _Kana_Lock
148 addStandard("KanjiMode", KeyTable.XK_Kanji);
149 addStandard("Katakana", KeyTable.XK_Katakana);
150 addStandard("Romaji", KeyTable.XK_Romaji);
151 addStandard("Zenkaku", KeyTable.XK_Zenkaku);
152 addStandard("ZenkakuHanaku", KeyTable.XK_Zenkaku_Hankaku);
153
154 // 2.9. General-Purpose Function Keys
155
156 addStandard("F1", KeyTable.XK_F1);
157 addStandard("F2", KeyTable.XK_F2);
158 addStandard("F3", KeyTable.XK_F3);
159 addStandard("F4", KeyTable.XK_F4);
160 addStandard("F5", KeyTable.XK_F5);
161 addStandard("F6", KeyTable.XK_F6);
162 addStandard("F7", KeyTable.XK_F7);
163 addStandard("F8", KeyTable.XK_F8);
164 addStandard("F9", KeyTable.XK_F9);
165 addStandard("F10", KeyTable.XK_F10);
166 addStandard("F11", KeyTable.XK_F11);
167 addStandard("F12", KeyTable.XK_F12);
168 addStandard("F13", KeyTable.XK_F13);
169 addStandard("F14", KeyTable.XK_F14);
170 addStandard("F15", KeyTable.XK_F15);
171 addStandard("F16", KeyTable.XK_F16);
172 addStandard("F17", KeyTable.XK_F17);
173 addStandard("F18", KeyTable.XK_F18);
174 addStandard("F19", KeyTable.XK_F19);
175 addStandard("F20", KeyTable.XK_F20);
176 addStandard("F21", KeyTable.XK_F21);
177 addStandard("F22", KeyTable.XK_F22);
178 addStandard("F23", KeyTable.XK_F23);
179 addStandard("F24", KeyTable.XK_F24);
180 addStandard("F25", KeyTable.XK_F25);
181 addStandard("F26", KeyTable.XK_F26);
182 addStandard("F27", KeyTable.XK_F27);
183 addStandard("F28", KeyTable.XK_F28);
184 addStandard("F29", KeyTable.XK_F29);
185 addStandard("F30", KeyTable.XK_F30);
186 addStandard("F31", KeyTable.XK_F31);
187 addStandard("F32", KeyTable.XK_F32);
188 addStandard("F33", KeyTable.XK_F33);
189 addStandard("F34", KeyTable.XK_F34);
190 addStandard("F35", KeyTable.XK_F35);
191 // - Soft1...
192
193 // 2.10. Multimedia Keys
194
195 // - ChannelDown
196 // - ChannelUp
197 addStandard("Close", KeyTable.XF86XK_Close);
198 addStandard("MailForward", KeyTable.XF86XK_MailForward);
199 addStandard("MailReply", KeyTable.XF86XK_Reply);
200 addStandard("MainSend", KeyTable.XF86XK_Send);
201 addStandard("MediaFastForward", KeyTable.XF86XK_AudioForward);
202 addStandard("MediaPause", KeyTable.XF86XK_AudioPause);
203 addStandard("MediaPlay", KeyTable.XF86XK_AudioPlay);
204 addStandard("MediaRecord", KeyTable.XF86XK_AudioRecord);
205 addStandard("MediaRewind", KeyTable.XF86XK_AudioRewind);
206 addStandard("MediaStop", KeyTable.XF86XK_AudioStop);
207 addStandard("MediaTrackNext", KeyTable.XF86XK_AudioNext);
208 addStandard("MediaTrackPrevious", KeyTable.XF86XK_AudioPrev);
209 addStandard("New", KeyTable.XF86XK_New);
210 addStandard("Open", KeyTable.XF86XK_Open);
211 addStandard("Print", KeyTable.XK_Print);
212 addStandard("Save", KeyTable.XF86XK_Save);
213 addStandard("SpellCheck", KeyTable.XF86XK_Spell);
214
215 // 2.11. Multimedia Numpad Keys
216
217 // - Key11
218 // - Key12
219
220 // 2.12. Audio Keys
221
222 // - AudioBalanceLeft
223 // - AudioBalanceRight
224 // - AudioBassDown
225 // - AudioBassBoostDown
226 // - AudioBassBoostToggle
227 // - AudioBassBoostUp
228 // - AudioBassUp
229 // - AudioFaderFront
230 // - AudioFaderRear
231 // - AudioSurroundModeNext
232 // - AudioTrebleDown
233 // - AudioTrebleUp
234 addStandard("AudioVolumeDown", KeyTable.XF86XK_AudioLowerVolume);
235 addStandard("AudioVolumeUp", KeyTable.XF86XK_AudioRaiseVolume);
236 addStandard("AudioVolumeMute", KeyTable.XF86XK_AudioMute);
237 // - MicrophoneToggle
238 // - MicrophoneVolumeDown
239 // - MicrophoneVolumeUp
240 addStandard("MicrophoneVolumeMute", KeyTable.XF86XK_AudioMicMute);
241
242 // 2.13. Speech Keys
243
244 // - SpeechCorrectionList
245 // - SpeechInputToggle
246
247 // 2.14. Application Keys
248
249 addStandard("LaunchCalculator", KeyTable.XF86XK_Calculator);
250 addStandard("LaunchCalendar", KeyTable.XF86XK_Calendar);
251 addStandard("LaunchMail", KeyTable.XF86XK_Mail);
252 addStandard("LaunchMediaPlayer", KeyTable.XF86XK_AudioMedia);
253 addStandard("LaunchMusicPlayer", KeyTable.XF86XK_Music);
254 addStandard("LaunchMyComputer", KeyTable.XF86XK_MyComputer);
255 addStandard("LaunchPhone", KeyTable.XF86XK_Phone);
256 addStandard("LaunchScreenSaver", KeyTable.XF86XK_ScreenSaver);
257 addStandard("LaunchSpreadsheet", KeyTable.XF86XK_Excel);
258 addStandard("LaunchWebBrowser", KeyTable.XF86XK_WWW);
259 addStandard("LaunchWebCam", KeyTable.XF86XK_WebCam);
260 addStandard("LaunchWordProcessor", KeyTable.XF86XK_Word);
261
262 // 2.15. Browser Keys
263
264 addStandard("BrowserBack", KeyTable.XF86XK_Back);
265 addStandard("BrowserFavorites", KeyTable.XF86XK_Favorites);
266 addStandard("BrowserForward", KeyTable.XF86XK_Forward);
267 addStandard("BrowserHome", KeyTable.XF86XK_HomePage);
268 addStandard("BrowserRefresh", KeyTable.XF86XK_Refresh);
269 addStandard("BrowserSearch", KeyTable.XF86XK_Search);
270 addStandard("BrowserStop", KeyTable.XF86XK_Stop);
271
272 // 2.16. Mobile Phone Keys
273
274 // - A whole bunch...
275
276 // 2.17. TV Keys
277
278 // - A whole bunch...
279
280 // 2.18. Media Controller Keys
281
282 // - A whole bunch...
283 addStandard("Dimmer", KeyTable.XF86XK_BrightnessAdjust);
284 addStandard("MediaAudioTrack", KeyTable.XF86XK_AudioCycleTrack);
285 addStandard("RandomToggle", KeyTable.XF86XK_AudioRandomPlay);
286 addStandard("SplitScreenToggle", KeyTable.XF86XK_SplitScreen);
287 addStandard("Subtitle", KeyTable.XF86XK_Subtitle);
288 addStandard("VideoModeNext", KeyTable.XF86XK_Next_VMode);
289
290 // Extra: Numpad
291
292 addNumpad("=", KeyTable.XK_equal, KeyTable.XK_KP_Equal);
293 addNumpad("+", KeyTable.XK_plus, KeyTable.XK_KP_Add);
294 addNumpad("-", KeyTable.XK_minus, KeyTable.XK_KP_Subtract);
295 addNumpad("*", KeyTable.XK_asterisk, KeyTable.XK_KP_Multiply);
296 addNumpad("/", KeyTable.XK_slash, KeyTable.XK_KP_Divide);
297 addNumpad(".", KeyTable.XK_period, KeyTable.XK_KP_Decimal);
298 addNumpad(",", KeyTable.XK_comma, KeyTable.XK_KP_Separator);
299 addNumpad("0", KeyTable.XK_0, KeyTable.XK_KP_0);
300 addNumpad("1", KeyTable.XK_1, KeyTable.XK_KP_1);
301 addNumpad("2", KeyTable.XK_2, KeyTable.XK_KP_2);
302 addNumpad("3", KeyTable.XK_3, KeyTable.XK_KP_3);
303 addNumpad("4", KeyTable.XK_4, KeyTable.XK_KP_4);
304 addNumpad("5", KeyTable.XK_5, KeyTable.XK_KP_5);
305 addNumpad("6", KeyTable.XK_6, KeyTable.XK_KP_6);
306 addNumpad("7", KeyTable.XK_7, KeyTable.XK_KP_7);
307 addNumpad("8", KeyTable.XK_8, KeyTable.XK_KP_8);
308 addNumpad("9", KeyTable.XK_9, KeyTable.XK_KP_9);
309
310 export default DOMKeyTable;