Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUACAMOLE-1823: Fix capslock on macos chrome #895

Open
wants to merge 2 commits into
base: patch
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions guacamole-common-js/src/main/webapp/modules/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ Guacamole.Keyboard = function Keyboard(element) {
altIsTypableOnly: false,

/**
* Whether we can rely on receiving a keyup event for the Caps Lock
* key.
* Whether we can rely on receiving a keyup or keydown event for the
* Caps Lock key.
*
* @type {!boolean}
*/
capsLockKeyupUnreliable: false
capsLockKeyEventUnreliable: false

};

Expand All @@ -127,10 +127,11 @@ Guacamole.Keyboard = function Keyboard(element) {
quirks.keyupUnreliable = true;

// The Alt key on Mac is never used for keyboard shortcuts, and the
// Caps Lock key never dispatches keyup events
// Caps Lock key never dispatches keyup events in firefox, and it
// dispatches either keydown or keyup events in chrome, but never both
else if (navigator.platform.match(/^mac/i)) {
quirks.altIsTypableOnly = true;
quirks.capsLockKeyupUnreliable = true;
quirks.capsLockKeyEventUnreliable = true;
}

}
Expand Down Expand Up @@ -289,7 +290,7 @@ Guacamole.Keyboard = function Keyboard(element) {
this.keyupReliable = false;

// We cannot rely on receiving keyup for Caps Lock on certain platforms
else if (this.keysym === 0xFFE5 && quirks.capsLockKeyupUnreliable)
else if (this.keysym === 0xFFE5 && quirks.capsLockKeyEventUnreliable)
this.keyupReliable = false;

// Determine whether default action for Alt+combinations must be prevented
Expand Down Expand Up @@ -355,6 +356,14 @@ Guacamole.Keyboard = function Keyboard(element) {
// We extend KeyEvent
KeyEvent.call(this, orig);

// If unreliable caps lock was pressed and event was not marked, then
// we need to pretend that this is a keydown event because we obviously
// did not receive it (issue on macos with chrome)
if (this.keyCode == 20 && quirks.capsLockKeyEventUnreliable) {
eventLog.push(new KeydownEvent(this));
return;
}

// If key is known from keyCode or DOM3 alone, use that (keyCode is
// still more reliable for keyup when dead keys are in use)
this.keysym = keysym_from_keycode(this.keyCode, this.location)
Expand Down