From b6b7a37000aa0a958fd08faf99dc74aab0137144 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 14 Jan 2018 20:44:22 -0800 Subject: [PATCH] GUACAMOLE-161: Do not rely on receiving keyup for Caps Lock on Mac (only keydown is dispatched). --- .../src/main/webapp/modules/Keyboard.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js index 7902e6ab4..48d7d5892 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -100,7 +100,15 @@ Guacamole.Keyboard = function Keyboard(element) { * * @type {Boolean} */ - altIsTypableOnly: false + altIsTypableOnly: false, + + /** + * Whether we can rely on receiving a keyup event for the Caps Lock + * key. + * + * @type {Boolean} + */ + capsLockKeyupUnreliable: false }; @@ -112,9 +120,12 @@ Guacamole.Keyboard = function Keyboard(element) { if (navigator.platform.match(/ipad|iphone|ipod/i)) quirks.keyupUnreliable = true; - // The Alt key on Mac is never used for keyboard shortcuts - else if (navigator.platform.match(/^mac/i)) + // The Alt key on Mac is never used for keyboard shortcuts, and the + // Caps Lock key never dispatches keyup events + else if (navigator.platform.match(/^mac/i)) { quirks.altIsTypableOnly = true; + quirks.capsLockKeyupUnreliable = true; + } } @@ -260,6 +271,10 @@ Guacamole.Keyboard = function Keyboard(element) { if (guac_keyboard.modifiers.meta && this.keysym !== 0xFFE7 && this.keysym !== 0xFFE8) this.keyupReliable = false; + // We cannot rely on receiving keyup for Caps Lock on certain platforms + else if (this.keysym === 0xFFE5 && quirks.capsLockKeyupUnreliable) + this.keyupReliable = false; + // Determine whether default action for Alt+combinations must be prevented var prevent_alt = !guac_keyboard.modifiers.ctrl && !quirks.altIsTypableOnly;