]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Handle CapsLock on macOS
authorPierre Ossman <ossman@cendio.se>
Thu, 4 May 2017 09:52:40 +0000 (11:52 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 4 May 2017 10:13:48 +0000 (12:13 +0200)
Modifiers behave a bit oddly on macOS, causing weird CapsLock events
to be sent by the browsers.

core/input/devices.js

index 2c9af31c6fcc14fe54d1716bf49c88631ad57e23..1efcfb5c3aefc1da9d2a642c8f6fc155b0adbb7d 100644 (file)
@@ -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;