From d9d7c4a61e8c5a2b7a7c969957dd4d5b931bcabc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 May 2012 13:44:17 -0700 Subject: [PATCH] Only release ctrl/alt in keypress handler if character is not a control character. Beware that this causes a regression in Firefox as it sends keypress for Alt+combinations and Ctrl+combinations even though they will not type anything. --- src/main/resources/keyboard.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/resources/keyboard.js b/src/main/resources/keyboard.js index 6787af8..c60759e 100644 --- a/src/main/resources/keyboard.js +++ b/src/main/resources/keyboard.js @@ -292,13 +292,22 @@ Guacamole.Keyboard = function(element) { } - function getKeySymFromCharCode(keyCode) { + function isControlCharacter(codepoint) { + return codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F); + } + + function getKeySymFromCharCode(codepoint) { - if (keyCode >= 0x0000 && keyCode <= 0x00FF) - return keyCode; + // Keysyms for control characters + if (isControlCharacter(codepoint)) return 0xFF00 | codepoint; - if (keyCode >= 0x0100 && keyCode <= 0x10FFFF) - return 0x01000000 | keyCode; + // Keysyms for ASCII chars + if (codepoint >= 0x0000 && codepoint <= 0x00FF) + return codepoint; + + // Keysyms for Unicode + if (codepoint >= 0x0100 && codepoint <= 0x10FFFF) + return 0x01000000 | codepoint; return null; @@ -399,8 +408,7 @@ Guacamole.Keyboard = function(element) { var codepoint = parseInt(hex, 16); // If control character, not typable - if (codepoint <= 0x1F) return false; - if (codepoint >= 0x7F && codepoint <= 0x9F) return false; + if (isControlCharacter(codepoint)) return false; // Otherwise, typable return true; @@ -465,10 +473,12 @@ Guacamole.Keyboard = function(element) { keypress_keysym = getKeySymFromCharCode(keynum); - // If event identified as a typable character (keypress involved) + // If event identified as a typable character // then release Ctrl and Alt (if pressed) - if (guac_keyboard.modifiers.ctrl) sendKeyReleased(0xFFE3); - if (guac_keyboard.modifiers.alt) sendKeyReleased(0xFFE9); + if (!isControlCharacter(keynum)) { + if (guac_keyboard.modifiers.ctrl) sendKeyReleased(0xFFE3); + if (guac_keyboard.modifiers.alt) sendKeyReleased(0xFFE9); + } // Defer handling of event until after any other pending // key events. -- 1.7.10.4