main
Raw Download raw file
  1/*
  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)
  5 */
  6
  7import 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
 16const DOMKeyTable = {};
 17
 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];
 22}
 23
 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];
 29}
 30
 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];
 36}
 37
 38// 3.2. Modifier Keys
 39
 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);
 44// - Fn
 45// - FnLock
 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);
 50// - Symbol
 51// - SymbolLock
 52// - Hyper
 53// - Super
 54
 55// 3.3. Whitespace Keys
 56
 57addNumpad("Enter", KeyTable.XK_Return, KeyTable.XK_KP_Enter);
 58addStandard("Tab", KeyTable.XK_Tab);
 59addNumpad(" ", KeyTable.XK_space, KeyTable.XK_KP_Space);
 60
 61// 3.4. Navigation Keys
 62
 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);
 71
 72// 3.5. Editing Keys
 73
 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
 77// that scenario.
 78addNumpad("Clear", KeyTable.XK_Clear, KeyTable.XK_KP_Begin);
 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// 3.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// 3.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// 3.8. IME and Composition Keys
122
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);
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("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);
153
154// 3.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// 3.10. Multimedia Keys
194
195// - ChannelDown
196// - ChannelUp
197addStandard("Close", KeyTable.XF86XK_Close);
198addStandard("MailForward", KeyTable.XF86XK_MailForward);
199addStandard("MailReply", KeyTable.XF86XK_Reply);
200addStandard("MailSend", KeyTable.XF86XK_Send);
201// - MediaClose
202addStandard("MediaFastForward", KeyTable.XF86XK_AudioForward);
203addStandard("MediaPause", KeyTable.XF86XK_AudioPause);
204addStandard("MediaPlay", KeyTable.XF86XK_AudioPlay);
205// - MediaPlayPause
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);
216
217// 3.11. Multimedia Numpad Keys
218
219// - Key11
220// - Key12
221
222// 3.12. Audio Keys
223
224// - AudioBalanceLeft
225// - AudioBalanceRight
226// - AudioBassBoostDown
227// - AudioBassBoostToggle
228// - AudioBassBoostUp
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// 3.13. Speech Keys
243
244// - SpeechCorrectionList
245// - SpeechInputToggle
246
247// 3.14. Application Keys
248
249addStandard("LaunchApplication1", KeyTable.XF86XK_MyComputer);
250addStandard("LaunchApplication2", KeyTable.XF86XK_Calculator);
251addStandard("LaunchCalendar", KeyTable.XF86XK_Calendar);
252// - LaunchContacts
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);
262
263// 3.15. Browser Keys
264
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);
272
273// 3.16. Mobile Phone Keys
274
275// - A whole bunch...
276
277// 3.17. TV Keys
278
279// - A whole bunch...
280
281// 3.18. Media Controller Keys
282
283// - A whole bunch...
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);
290
291// Extra: Numpad
292
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);
310
311export default DOMKeyTable;