]> git.proxmox.com Git - mirror_novnc.git/blame - core/input/domkeytable.js
Prefer const/let over var
[mirror_novnc.git] / core / input / domkeytable.js
CommitLineData
9782d4a3
PO
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
afb621d5 7import KeyTable from "./keysym.js";
9782d4a3
PO
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
2b5f94fa 16const DOMKeyTable = {};
9782d4a3
PO
17
18function 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
25function 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
33function 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
43addLeftRight("Alt", KeyTable.XK_Alt_L, KeyTable.XK_Alt_R);
44addStandard("AltGraph", KeyTable.XK_ISO_Level3_Shift);
45addStandard("CapsLock", KeyTable.XK_Caps_Lock);
46addLeftRight("Control", KeyTable.XK_Control_L, KeyTable.XK_Control_R);
47// - Fn
48// - FnLock
49addLeftRight("Hyper", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
50addLeftRight("Meta", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
51addStandard("NumLock", KeyTable.XK_Num_Lock);
52addStandard("ScrollLock", KeyTable.XK_Scroll_Lock);
53addLeftRight("Shift", KeyTable.XK_Shift_L, KeyTable.XK_Shift_R);
54addLeftRight("Super", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
55// - Symbol
56// - SymbolLock
57
58// 2.3. Whitespace Keys
59
60addNumpad("Enter", KeyTable.XK_Return, KeyTable.XK_KP_Enter);
61addStandard("Tab", KeyTable.XK_Tab);
62addNumpad(" ", KeyTable.XK_space, KeyTable.XK_KP_Space);
63
64// 2.4. Navigation Keys
65
66addNumpad("ArrowDown", KeyTable.XK_Down, KeyTable.XK_KP_Down);
67addNumpad("ArrowUp", KeyTable.XK_Up, KeyTable.XK_KP_Up);
68addNumpad("ArrowLeft", KeyTable.XK_Left, KeyTable.XK_KP_Left);
69addNumpad("ArrowRight", KeyTable.XK_Right, KeyTable.XK_KP_Right);
70addNumpad("End", KeyTable.XK_End, KeyTable.XK_KP_End);
71addNumpad("Home", KeyTable.XK_Home, KeyTable.XK_KP_Home);
72addNumpad("PageDown", KeyTable.XK_Next, KeyTable.XK_KP_Next);
73addNumpad("PageUp", KeyTable.XK_Prior, KeyTable.XK_KP_Prior);
74
75// 2.5. Editing Keys
76
77addStandard("Backspace", KeyTable.XK_BackSpace);
78addStandard("Clear", KeyTable.XK_Clear);
79addStandard("Copy", KeyTable.XF86XK_Copy);
80// - CrSel
81addStandard("Cut", KeyTable.XF86XK_Cut);
82addNumpad("Delete", KeyTable.XK_Delete, KeyTable.XK_KP_Delete);
83// - EraseEof
84// - ExSel
85addNumpad("Insert", KeyTable.XK_Insert, KeyTable.XK_KP_Insert);
86addStandard("Paste", KeyTable.XF86XK_Paste);
87addStandard("Redo", KeyTable.XK_Redo);
88addStandard("Undo", KeyTable.XK_Undo);
89
90// 2.6. UI Keys
91
92// - Accept
93// - Again (could just be XK_Redo)
94// - Attn
95addStandard("Cancel", KeyTable.XK_Cancel);
96addStandard("ContextMenu", KeyTable.XK_Menu);
97addStandard("Escape", KeyTable.XK_Escape);
98addStandard("Execute", KeyTable.XK_Execute);
99addStandard("Find", KeyTable.XK_Find);
100addStandard("Help", KeyTable.XK_Help);
101addStandard("Pause", KeyTable.XK_Pause);
102// - Play
103// - Props
104addStandard("Select", KeyTable.XK_Select);
105addStandard("ZoomIn", KeyTable.XF86XK_ZoomIn);
106addStandard("ZoomOut", KeyTable.XF86XK_ZoomOut);
107
108// 2.7. Device Keys
109
110addStandard("BrightnessDown", KeyTable.XF86XK_MonBrightnessDown);
111addStandard("BrightnessUp", KeyTable.XF86XK_MonBrightnessUp);
112addStandard("Eject", KeyTable.XF86XK_Eject);
113addStandard("LogOff", KeyTable.XF86XK_LogOff);
114addStandard("Power", KeyTable.XF86XK_PowerOff);
115addStandard("PowerOff", KeyTable.XF86XK_PowerDown);
116addStandard("PrintScreen", KeyTable.XK_Print);
117addStandard("Hibernate", KeyTable.XF86XK_Hibernate);
118addStandard("Standby", KeyTable.XF86XK_Standby);
119addStandard("WakeUp", KeyTable.XF86XK_WakeUp);
120
121// 2.8. IME and Composition Keys
122
123addStandard("AllCandidates", KeyTable.XK_MultipleCandidate);
124addStandard("Alphanumeric", KeyTable.XK_Eisu_Shift); // could also be _Eisu_Toggle
125addStandard("CodeInput", KeyTable.XK_Codeinput);
126addStandard("Compose", KeyTable.XK_Multi_key);
127addStandard("Convert", KeyTable.XK_Henkan);
128// - Dead
129// - FinalMode
130addStandard("GroupFirst", KeyTable.XK_ISO_First_Group);
131addStandard("GroupLast", KeyTable.XK_ISO_Last_Group);
132addStandard("GroupNext", KeyTable.XK_ISO_Next_Group);
133addStandard("GroupPrevious", KeyTable.XK_ISO_Prev_Group);
134// - ModeChange (XK_Mode_switch is often used for AltGr)
135// - NextCandidate
136addStandard("NonConvert", KeyTable.XK_Muhenkan);
137addStandard("PreviousCandidate", KeyTable.XK_PreviousCandidate);
138// - Process
139addStandard("SingleCandidate", KeyTable.XK_SingleCandidate);
140addStandard("HangulMode", KeyTable.XK_Hangul);
141addStandard("HanjaMode", KeyTable.XK_Hangul_Hanja);
142addStandard("JunjuaMode", KeyTable.XK_Hangul_Jeonja);
143addStandard("Eisu", KeyTable.XK_Eisu_toggle);
144addStandard("Hankaku", KeyTable.XK_Hankaku);
145addStandard("Hiragana", KeyTable.XK_Hiragana);
146addStandard("HiraganaKatakana", KeyTable.XK_Hiragana_Katakana);
147addStandard("KanaMode", KeyTable.XK_Kana_Shift); // could also be _Kana_Lock
148addStandard("KanjiMode", KeyTable.XK_Kanji);
149addStandard("Katakana", KeyTable.XK_Katakana);
150addStandard("Romaji", KeyTable.XK_Romaji);
151addStandard("Zenkaku", KeyTable.XK_Zenkaku);
152addStandard("ZenkakuHanaku", KeyTable.XK_Zenkaku_Hankaku);
153
154// 2.9. General-Purpose Function Keys
155
156addStandard("F1", KeyTable.XK_F1);
157addStandard("F2", KeyTable.XK_F2);
158addStandard("F3", KeyTable.XK_F3);
159addStandard("F4", KeyTable.XK_F4);
160addStandard("F5", KeyTable.XK_F5);
161addStandard("F6", KeyTable.XK_F6);
162addStandard("F7", KeyTable.XK_F7);
163addStandard("F8", KeyTable.XK_F8);
164addStandard("F9", KeyTable.XK_F9);
165addStandard("F10", KeyTable.XK_F10);
166addStandard("F11", KeyTable.XK_F11);
167addStandard("F12", KeyTable.XK_F12);
168addStandard("F13", KeyTable.XK_F13);
169addStandard("F14", KeyTable.XK_F14);
170addStandard("F15", KeyTable.XK_F15);
171addStandard("F16", KeyTable.XK_F16);
172addStandard("F17", KeyTable.XK_F17);
173addStandard("F18", KeyTable.XK_F18);
174addStandard("F19", KeyTable.XK_F19);
175addStandard("F20", KeyTable.XK_F20);
176addStandard("F21", KeyTable.XK_F21);
177addStandard("F22", KeyTable.XK_F22);
178addStandard("F23", KeyTable.XK_F23);
179addStandard("F24", KeyTable.XK_F24);
180addStandard("F25", KeyTable.XK_F25);
181addStandard("F26", KeyTable.XK_F26);
182addStandard("F27", KeyTable.XK_F27);
183addStandard("F28", KeyTable.XK_F28);
184addStandard("F29", KeyTable.XK_F29);
185addStandard("F30", KeyTable.XK_F30);
186addStandard("F31", KeyTable.XK_F31);
187addStandard("F32", KeyTable.XK_F32);
188addStandard("F33", KeyTable.XK_F33);
189addStandard("F34", KeyTable.XK_F34);
190addStandard("F35", KeyTable.XK_F35);
191// - Soft1...
192
193// 2.10. Multimedia Keys
194
195// - ChannelDown
196// - ChannelUp
197addStandard("Close", KeyTable.XF86XK_Close);
198addStandard("MailForward", KeyTable.XF86XK_MailForward);
199addStandard("MailReply", KeyTable.XF86XK_Reply);
200addStandard("MainSend", KeyTable.XF86XK_Send);
201addStandard("MediaFastForward", KeyTable.XF86XK_AudioForward);
202addStandard("MediaPause", KeyTable.XF86XK_AudioPause);
203addStandard("MediaPlay", KeyTable.XF86XK_AudioPlay);
204addStandard("MediaRecord", KeyTable.XF86XK_AudioRecord);
205addStandard("MediaRewind", KeyTable.XF86XK_AudioRewind);
206addStandard("MediaStop", KeyTable.XF86XK_AudioStop);
207addStandard("MediaTrackNext", KeyTable.XF86XK_AudioNext);
208addStandard("MediaTrackPrevious", KeyTable.XF86XK_AudioPrev);
209addStandard("New", KeyTable.XF86XK_New);
210addStandard("Open", KeyTable.XF86XK_Open);
211addStandard("Print", KeyTable.XK_Print);
212addStandard("Save", KeyTable.XF86XK_Save);
213addStandard("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
234addStandard("AudioVolumeDown", KeyTable.XF86XK_AudioLowerVolume);
235addStandard("AudioVolumeUp", KeyTable.XF86XK_AudioRaiseVolume);
236addStandard("AudioVolumeMute", KeyTable.XF86XK_AudioMute);
237// - MicrophoneToggle
238// - MicrophoneVolumeDown
239// - MicrophoneVolumeUp
240addStandard("MicrophoneVolumeMute", KeyTable.XF86XK_AudioMicMute);
241
242// 2.13. Speech Keys
243
244// - SpeechCorrectionList
245// - SpeechInputToggle
246
247// 2.14. Application Keys
248
249addStandard("LaunchCalculator", KeyTable.XF86XK_Calculator);
250addStandard("LaunchCalendar", KeyTable.XF86XK_Calendar);
251addStandard("LaunchMail", KeyTable.XF86XK_Mail);
252addStandard("LaunchMediaPlayer", KeyTable.XF86XK_AudioMedia);
253addStandard("LaunchMusicPlayer", KeyTable.XF86XK_Music);
254addStandard("LaunchMyComputer", KeyTable.XF86XK_MyComputer);
255addStandard("LaunchPhone", KeyTable.XF86XK_Phone);
256addStandard("LaunchScreenSaver", KeyTable.XF86XK_ScreenSaver);
257addStandard("LaunchSpreadsheet", KeyTable.XF86XK_Excel);
258addStandard("LaunchWebBrowser", KeyTable.XF86XK_WWW);
259addStandard("LaunchWebCam", KeyTable.XF86XK_WebCam);
260addStandard("LaunchWordProcessor", KeyTable.XF86XK_Word);
261
262// 2.15. Browser Keys
263
264addStandard("BrowserBack", KeyTable.XF86XK_Back);
265addStandard("BrowserFavorites", KeyTable.XF86XK_Favorites);
266addStandard("BrowserForward", KeyTable.XF86XK_Forward);
267addStandard("BrowserHome", KeyTable.XF86XK_HomePage);
268addStandard("BrowserRefresh", KeyTable.XF86XK_Refresh);
269addStandard("BrowserSearch", KeyTable.XF86XK_Search);
270addStandard("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...
283addStandard("Dimmer", KeyTable.XF86XK_BrightnessAdjust);
284addStandard("MediaAudioTrack", KeyTable.XF86XK_AudioCycleTrack);
285addStandard("RandomToggle", KeyTable.XF86XK_AudioRandomPlay);
286addStandard("SplitScreenToggle", KeyTable.XF86XK_SplitScreen);
287addStandard("Subtitle", KeyTable.XF86XK_Subtitle);
288addStandard("VideoModeNext", KeyTable.XF86XK_Next_VMode);
289
290// Extra: Numpad
291
292addNumpad("=", KeyTable.XK_equal, KeyTable.XK_KP_Equal);
293addNumpad("+", KeyTable.XK_plus, KeyTable.XK_KP_Add);
294addNumpad("-", KeyTable.XK_minus, KeyTable.XK_KP_Subtract);
295addNumpad("*", KeyTable.XK_asterisk, KeyTable.XK_KP_Multiply);
296addNumpad("/", KeyTable.XK_slash, KeyTable.XK_KP_Divide);
297addNumpad(".", KeyTable.XK_period, KeyTable.XK_KP_Decimal);
298addNumpad(",", KeyTable.XK_comma, KeyTable.XK_KP_Separator);
299addNumpad("0", KeyTable.XK_0, KeyTable.XK_KP_0);
300addNumpad("1", KeyTable.XK_1, KeyTable.XK_KP_1);
301addNumpad("2", KeyTable.XK_2, KeyTable.XK_KP_2);
302addNumpad("3", KeyTable.XK_3, KeyTable.XK_KP_3);
303addNumpad("4", KeyTable.XK_4, KeyTable.XK_KP_4);
304addNumpad("5", KeyTable.XK_5, KeyTable.XK_KP_5);
305addNumpad("6", KeyTable.XK_6, KeyTable.XK_KP_6);
306addNumpad("7", KeyTable.XK_7, KeyTable.XK_KP_7);
307addNumpad("8", KeyTable.XK_8, KeyTable.XK_KP_8);
308addNumpad("9", KeyTable.XK_9, KeyTable.XK_KP_9);
309
310export default DOMKeyTable;