2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2018 The noVNC Authors
4 * Licensed under MPL 2.0 or any later version (see LICENSE.txt)
7import KeyTable from "./keysym.js";
10 * Mapping between HTML key values and VNC/X11 keysyms for "special"
11 * keys that cannot be handled via their Unicode codepoint.
13 * See https://www.w3.org/TR/uievents-key/ for possible values.
16const DOMKeyTable = {};
18function addStandard(key, standard) {
19 if (standard === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
20 if (key in DOMKeyTable) throw new Error("Duplicate entry for key \"" + key + "\"");
21 DOMKeyTable[key] = [standard, standard, standard, standard];
24function addLeftRight(key, left, right) {
25 if (left === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
26 if (right === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
27 if (key in DOMKeyTable) throw new Error("Duplicate entry for key \"" + key + "\"");
28 DOMKeyTable[key] = [left, left, right, left];
31function addNumpad(key, standard, numpad) {
32 if (standard === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
33 if (numpad === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
34 if (key in DOMKeyTable) throw new Error("Duplicate entry for key \"" + key + "\"");
35 DOMKeyTable[key] = [standard, standard, standard, numpad];
40addLeftRight("Alt", KeyTable.XK_Alt_L, KeyTable.XK_Alt_R);
41addStandard("AltGraph", KeyTable.XK_ISO_Level3_Shift);
42addStandard("CapsLock", KeyTable.XK_Caps_Lock);
43addLeftRight("Control", KeyTable.XK_Control_L, KeyTable.XK_Control_R);
46addLeftRight("Meta", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
47addStandard("NumLock", KeyTable.XK_Num_Lock);
48addStandard("ScrollLock", KeyTable.XK_Scroll_Lock);
49addLeftRight("Shift", KeyTable.XK_Shift_L, KeyTable.XK_Shift_R);
55// 3.3. Whitespace Keys
57addNumpad("Enter", KeyTable.XK_Return, KeyTable.XK_KP_Enter);
58addStandard("Tab", KeyTable.XK_Tab);
59addNumpad(" ", KeyTable.XK_space, KeyTable.XK_KP_Space);
61// 3.4. Navigation Keys
63addNumpad("ArrowDown", KeyTable.XK_Down, KeyTable.XK_KP_Down);
64addNumpad("ArrowLeft", KeyTable.XK_Left, KeyTable.XK_KP_Left);
65addNumpad("ArrowRight", KeyTable.XK_Right, KeyTable.XK_KP_Right);
66addNumpad("ArrowUp", KeyTable.XK_Up, KeyTable.XK_KP_Up);
67addNumpad("End", KeyTable.XK_End, KeyTable.XK_KP_End);
68addNumpad("Home", KeyTable.XK_Home, KeyTable.XK_KP_Home);
69addNumpad("PageDown", KeyTable.XK_Next, KeyTable.XK_KP_Next);
70addNumpad("PageUp", KeyTable.XK_Prior, KeyTable.XK_KP_Prior);
74addStandard("Backspace", KeyTable.XK_BackSpace);
75// Browsers send "Clear" for the numpad 5 without NumLock because
76// Windows uses VK_Clear for that key. But Unix expects KP_Begin for
78addNumpad("Clear", KeyTable.XK_Clear, KeyTable.XK_KP_Begin);
79addStandard("Copy", KeyTable.XF86XK_Copy);
81addStandard("Cut", KeyTable.XF86XK_Cut);
82addNumpad("Delete", KeyTable.XK_Delete, KeyTable.XK_KP_Delete);
85addNumpad("Insert", KeyTable.XK_Insert, KeyTable.XK_KP_Insert);
86addStandard("Paste", KeyTable.XF86XK_Paste);
87addStandard("Redo", KeyTable.XK_Redo);
88addStandard("Undo", KeyTable.XK_Undo);
93// - Again (could just be XK_Redo)
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);
104addStandard("Select", KeyTable.XK_Select);
105addStandard("ZoomIn", KeyTable.XF86XK_ZoomIn);
106addStandard("ZoomOut", KeyTable.XF86XK_ZoomOut);
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);
121// 3.8. IME and Composition Keys
123addStandard("AllCandidates", KeyTable.XK_MultipleCandidate);
124addStandard("Alphanumeric", KeyTable.XK_Eisu_toggle);
125addStandard("CodeInput", KeyTable.XK_Codeinput);
126addStandard("Compose", KeyTable.XK_Multi_key);
127addStandard("Convert", KeyTable.XK_Henkan);
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)
136addStandard("NonConvert", KeyTable.XK_Muhenkan);
137addStandard("PreviousCandidate", KeyTable.XK_PreviousCandidate);
139addStandard("SingleCandidate", KeyTable.XK_SingleCandidate);
140addStandard("HangulMode", KeyTable.XK_Hangul);
141addStandard("HanjaMode", KeyTable.XK_Hangul_Hanja);
142addStandard("JunjaMode", 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("ZenkakuHankaku", KeyTable.XK_Zenkaku_Hankaku);
154// 3.9. General-Purpose Function Keys
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);
193// 3.10. Multimedia Keys
197addStandard("Close", KeyTable.XF86XK_Close);
198addStandard("MailForward", KeyTable.XF86XK_MailForward);
199addStandard("MailReply", KeyTable.XF86XK_Reply);
200addStandard("MailSend", KeyTable.XF86XK_Send);
202addStandard("MediaFastForward", KeyTable.XF86XK_AudioForward);
203addStandard("MediaPause", KeyTable.XF86XK_AudioPause);
204addStandard("MediaPlay", KeyTable.XF86XK_AudioPlay);
206addStandard("MediaRecord", KeyTable.XF86XK_AudioRecord);
207addStandard("MediaRewind", KeyTable.XF86XK_AudioRewind);
208addStandard("MediaStop", KeyTable.XF86XK_AudioStop);
209addStandard("MediaTrackNext", KeyTable.XF86XK_AudioNext);
210addStandard("MediaTrackPrevious", KeyTable.XF86XK_AudioPrev);
211addStandard("New", KeyTable.XF86XK_New);
212addStandard("Open", KeyTable.XF86XK_Open);
213addStandard("Print", KeyTable.XK_Print);
214addStandard("Save", KeyTable.XF86XK_Save);
215addStandard("SpellCheck", KeyTable.XF86XK_Spell);
217// 3.11. Multimedia Numpad Keys
225// - AudioBalanceRight
226// - AudioBassBoostDown
227// - AudioBassBoostToggle
231// - AudioSurroundModeNext
234addStandard("AudioVolumeDown", KeyTable.XF86XK_AudioLowerVolume);
235addStandard("AudioVolumeUp", KeyTable.XF86XK_AudioRaiseVolume);
236addStandard("AudioVolumeMute", KeyTable.XF86XK_AudioMute);
238// - MicrophoneVolumeDown
239// - MicrophoneVolumeUp
240addStandard("MicrophoneVolumeMute", KeyTable.XF86XK_AudioMicMute);
244// - SpeechCorrectionList
245// - SpeechInputToggle
247// 3.14. Application Keys
249addStandard("LaunchApplication1", KeyTable.XF86XK_MyComputer);
250addStandard("LaunchApplication2", KeyTable.XF86XK_Calculator);
251addStandard("LaunchCalendar", KeyTable.XF86XK_Calendar);
253addStandard("LaunchMail", KeyTable.XF86XK_Mail);
254addStandard("LaunchMediaPlayer", KeyTable.XF86XK_AudioMedia);
255addStandard("LaunchMusicPlayer", KeyTable.XF86XK_Music);
256addStandard("LaunchPhone", KeyTable.XF86XK_Phone);
257addStandard("LaunchScreenSaver", KeyTable.XF86XK_ScreenSaver);
258addStandard("LaunchSpreadsheet", KeyTable.XF86XK_Excel);
259addStandard("LaunchWebBrowser", KeyTable.XF86XK_WWW);
260addStandard("LaunchWebCam", KeyTable.XF86XK_WebCam);
261addStandard("LaunchWordProcessor", KeyTable.XF86XK_Word);
265addStandard("BrowserBack", KeyTable.XF86XK_Back);
266addStandard("BrowserFavorites", KeyTable.XF86XK_Favorites);
267addStandard("BrowserForward", KeyTable.XF86XK_Forward);
268addStandard("BrowserHome", KeyTable.XF86XK_HomePage);
269addStandard("BrowserRefresh", KeyTable.XF86XK_Refresh);
270addStandard("BrowserSearch", KeyTable.XF86XK_Search);
271addStandard("BrowserStop", KeyTable.XF86XK_Stop);
273// 3.16. Mobile Phone Keys
281// 3.18. Media Controller Keys
284addStandard("Dimmer", KeyTable.XF86XK_BrightnessAdjust);
285addStandard("MediaAudioTrack", KeyTable.XF86XK_AudioCycleTrack);
286addStandard("RandomToggle", KeyTable.XF86XK_AudioRandomPlay);
287addStandard("SplitScreenToggle", KeyTable.XF86XK_SplitScreen);
288addStandard("Subtitle", KeyTable.XF86XK_Subtitle);
289addStandard("VideoModeNext", KeyTable.XF86XK_Next_VMode);
293addNumpad("=", KeyTable.XK_equal, KeyTable.XK_KP_Equal);
294addNumpad("+", KeyTable.XK_plus, KeyTable.XK_KP_Add);
295addNumpad("-", KeyTable.XK_minus, KeyTable.XK_KP_Subtract);
296addNumpad("*", KeyTable.XK_asterisk, KeyTable.XK_KP_Multiply);
297addNumpad("/", KeyTable.XK_slash, KeyTable.XK_KP_Divide);
298addNumpad(".", KeyTable.XK_period, KeyTable.XK_KP_Decimal);
299addNumpad(",", KeyTable.XK_comma, KeyTable.XK_KP_Separator);
300addNumpad("0", KeyTable.XK_0, KeyTable.XK_KP_0);
301addNumpad("1", KeyTable.XK_1, KeyTable.XK_KP_1);
302addNumpad("2", KeyTable.XK_2, KeyTable.XK_KP_2);
303addNumpad("3", KeyTable.XK_3, KeyTable.XK_KP_3);
304addNumpad("4", KeyTable.XK_4, KeyTable.XK_KP_4);
305addNumpad("5", KeyTable.XK_5, KeyTable.XK_KP_5);
306addNumpad("6", KeyTable.XK_6, KeyTable.XK_KP_6);
307addNumpad("7", KeyTable.XK_7, KeyTable.XK_KP_7);
308addNumpad("8", KeyTable.XK_8, KeyTable.XK_KP_8);
309addNumpad("9", KeyTable.XK_9, KeyTable.XK_KP_9);
311export default DOMKeyTable;