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

Ensure shifted keys are released #735

Open
wants to merge 1 commit into
base: main
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
27 changes: 27 additions & 0 deletions guacamole-common-js/src/main/webapp/modules/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,17 @@ Guacamole.Keyboard = function Keyboard(element) {
0xFFEC: true // Right super/hyper
};

/**
* Keeps all key code pressed while holding SHIFT key.
* The keys will be released (keyup) when SHIFT key is released to
* ensure client receives the corret keyup event for the shifted key.
* Use case:
* You press SHIFT + . sending a ":" key code
* You release SHIFT key first, shiftedKeys has a ":" so it's released as well.
*/
this.shiftedKeys = {}


/**
* All modifiers and their states.
*
Expand Down Expand Up @@ -1312,6 +1323,10 @@ Guacamole.Keyboard = function Keyboard(element) {
// Ignore events which have already been handled
if (!markEvent(e)) return;

if (e.shiftKey && e.keyCode !== 16) {
guac_keyboard.shiftedKeys[e.code] = e
}

var keydownEvent = new KeydownEvent(e);

// Ignore (but do not prevent) the "composition" keycode sent by some
Expand Down Expand Up @@ -1355,6 +1370,18 @@ Guacamole.Keyboard = function Keyboard(element) {
// Ignore events which have already been handled
if (!markEvent(e)) return;

// Check if we have to release shifted keys first
if (e.keyCode === 16 /* SHIFT */) {
const evs = Object.values(guac_keyboard.shiftedKeys)
evs.forEach(e => {
eventLog.push(new KeyupEvent(e));
interpret_events();
})
guac_keyboard.shiftedKeys = {}
} else if (guac_keyboard.shiftedKeys[e.keyCode]) {
delete guac_keyboard.shiftedKeys[e.keyCode]
}

e.preventDefault();

// Log event, call for interpretation
Expand Down