MCPcopy Create free account
hub / github.com/apache/cloudstack / _handleKeyDown

Method _handleKeyDown

systemvm/agent/noVNC/core/input/keyboard.js:87–212  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

85 }
86
87 _handleKeyDown(e) {
88 const code = this._getKeyCode(e);
89 let keysym = KeyboardUtil.getKeysym(e);
90 let numlock = e.getModifierState('NumLock');
91 let capslock = e.getModifierState('CapsLock');
92
93 // getModifierState for NumLock is not supported on mac and ios and always returns false.
94 // Set to null to indicate unknown/unsupported instead.
95 if (browser.isMac() || browser.isIOS()) {
96 numlock = null;
97 }
98
99 // Windows doesn't have a proper AltGr, but handles it using
100 // fake Ctrl+Alt. However the remote end might not be Windows,
101 // so we need to merge those in to a single AltGr event. We
102 // detect this case by seeing the two key events directly after
103 // each other with a very short time between them (<50ms).
104 if (this._altGrArmed) {
105 this._altGrArmed = false;
106 clearTimeout(this._altGrTimeout);
107
108 if ((code === "AltRight") &&
109 ((e.timeStamp - this._altGrCtrlTime) < 50)) {
110 // FIXME: We fail to detect this if either Ctrl key is
111 // first manually pressed as Windows then no
112 // longer sends the fake Ctrl down event. It
113 // does however happily send real Ctrl events
114 // even when AltGr is already down. Some
115 // browsers detect this for us though and set the
116 // key to "AltGraph".
117 keysym = KeyTable.XK_ISO_Level3_Shift;
118 } else {
119 this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true, numlock, capslock);
120 }
121 }
122
123 // We cannot handle keys we cannot track, but we also need
124 // to deal with virtual keyboards which omit key info
125 if (code === 'Unidentified') {
126 if (keysym) {
127 // If it's a virtual keyboard then it should be
128 // sufficient to just send press and release right
129 // after each other
130 this._sendKeyEvent(keysym, code, true, numlock, capslock);
131 this._sendKeyEvent(keysym, code, false, numlock, capslock);
132 }
133
134 stopEvent(e);
135 return;
136 }
137
138 // Alt behaves more like AltGraph on macOS, so shuffle the
139 // keys around a bit to make things more sane for the remote
140 // server. This method is used by RealVNC and TigerVNC (and
141 // possibly others).
142 if (browser.isMac() || browser.isIOS()) {
143 switch (keysym) {
144 case KeyTable.XK_Super_L:

Callers

nothing calls this directly

Calls 4

_getKeyCodeMethod · 0.95
_sendKeyEventMethod · 0.95
stopEventFunction · 0.90
isWindowsMethod · 0.45

Tested by

no test coverage detected