summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2017-05-04 11:52:40 +0200
committerPierre Ossman <ossman@cendio.se>2017-05-04 12:13:48 +0200
commit634cc1ba46222125c7680472a234126e875cfc3d (patch)
tree4efdb198ad87fb28ec35a4db143b64abda301539
parentbf43c26319a7bfea989a2306c9423feac0509c32 (diff)
downloadnovnc-634cc1ba46222125c7680472a234126e875cfc3d.tar.gz
Handle CapsLock on macOS
Modifiers behave a bit oddly on macOS, causing weird CapsLock events to be sent by the browsers.
-rw-r--r--core/input/devices.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/input/devices.js b/core/input/devices.js
index 2c9af31..1efcfb5 100644
--- a/core/input/devices.js
+++ b/core/input/devices.js
@@ -146,6 +146,17 @@ Keyboard.prototype = {
keysym = this._keyDownList[code];
}
+ // macOS doesn't send proper key events for modifiers, only
+ // state change events. That gets extra confusing for CapsLock
+ // which toggles on each press, but not on release. So pretend
+ // it was a quick press and release of the button.
+ if (isMac() && (code === 'CapsLock')) {
+ this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
+ this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
+ stopEvent(e);
+ return;
+ }
+
// If this is a legacy browser then we'll need to wait for
// a keypress event as well
if (!keysym) {
@@ -200,6 +211,13 @@ Keyboard.prototype = {
var code = this._getKeyCode(e);
+ // See comment in _handleKeyDown()
+ if (isMac() && (code === 'CapsLock')) {
+ this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
+ this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
+ return;
+ }
+
// Do we really think this key is down?
if (!(code in this._keyDownList)) {
return;