mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
Streamline identifier parse logic, ensure case is consistent across browsers, use keyIdentifier if it exists and a corresponding keypress is unlikely.
This commit is contained in:
@@ -330,33 +330,32 @@ Guacamole.Keyboard = function(element) {
|
|||||||
|
|
||||||
function keysym_from_key_identifier(shifted, identifier, location) {
|
function keysym_from_key_identifier(shifted, identifier, location) {
|
||||||
|
|
||||||
// If identifier is U+xxxx, decode Unicode codepoint
|
var typedCharacter;
|
||||||
|
|
||||||
|
// If identifier is U+xxxx, decode Unicode character
|
||||||
var unicodePrefixLocation = identifier.indexOf("U+");
|
var unicodePrefixLocation = identifier.indexOf("U+");
|
||||||
if (unicodePrefixLocation >= 0) {
|
if (unicodePrefixLocation >= 0) {
|
||||||
|
|
||||||
var hex = identifier.substring(unicodePrefixLocation+2);
|
var hex = identifier.substring(unicodePrefixLocation+2);
|
||||||
var codepoint = parseInt(hex, 16);
|
typedCharacter = String.fromCharCode(parseInt(hex, 16));
|
||||||
var typedCharacter;
|
|
||||||
|
|
||||||
// Convert case if shifted
|
|
||||||
if (!shifted)
|
|
||||||
typedCharacter = String.fromCharCode(codepoint).toLowerCase();
|
|
||||||
else
|
|
||||||
typedCharacter = String.fromCharCode(codepoint).toUpperCase();
|
|
||||||
|
|
||||||
// Get codepoint
|
|
||||||
codepoint = typedCharacter.charCodeAt(0);
|
|
||||||
return keysym_from_charcode(codepoint);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If single character, return keysym from codepoint
|
// If single character, use that as typed character
|
||||||
if (identifier.length === 1) {
|
else if (identifier.length === 1)
|
||||||
var codepoint = identifier.charCodeAt(0);
|
typedCharacter = identifier;
|
||||||
return keysym_from_charcode(codepoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
return get_keysym(keyidentifier_keysym[identifier], location);
|
// Otherwise, look up corresponding keysym
|
||||||
|
else
|
||||||
|
return get_keysym(keyidentifier_keysym[identifier], location);
|
||||||
|
|
||||||
|
// Convert case if shifted
|
||||||
|
if (shifted)
|
||||||
|
typedCharacter = typedCharacter.toUpperCase();
|
||||||
|
else
|
||||||
|
typedCharacter = typedCharacter.toLowerCase();
|
||||||
|
|
||||||
|
// Get codepoint
|
||||||
|
var codepoint = typedCharacter.charCodeAt(0);
|
||||||
|
return keysym_from_charcode(codepoint);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +509,6 @@ Guacamole.Keyboard = function(element) {
|
|||||||
|
|
||||||
// Get key location
|
// Get key location
|
||||||
var location = e.location || e.keyLocation || 0;
|
var location = e.location || e.keyLocation || 0;
|
||||||
var identifier = e.key;
|
|
||||||
|
|
||||||
// Ignore any unknown key events
|
// Ignore any unknown key events
|
||||||
if (!keynum && !identifier) {
|
if (!keynum && !identifier) {
|
||||||
@@ -530,11 +528,24 @@ Guacamole.Keyboard = function(element) {
|
|||||||
// Try to get keysym from keycode
|
// Try to get keysym from keycode
|
||||||
var keysym = keysym_from_keycode(keynum, location);
|
var keysym = keysym_from_keycode(keynum, location);
|
||||||
|
|
||||||
// Also try to get get keysym from identifier
|
// Also try to get get keysym from e.key
|
||||||
if (identifier)
|
if (e.key)
|
||||||
keysym = keysym ||
|
keysym = keysym || keysym_from_key_identifier(
|
||||||
keysym_from_key_identifier(guac_keyboard.modifiers.shift,
|
guac_keyboard.modifiers.shift, e.key, location);
|
||||||
identifier, location);
|
|
||||||
|
// If no e.key, use e.keyIdentifier if absolutely necessary (can be buggy)
|
||||||
|
else {
|
||||||
|
|
||||||
|
var keypress_unlikely =
|
||||||
|
(guac_keyboard.modifiers.ctrl && !guac_keyboard.modifiers.alt)
|
||||||
|
|| (!guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt)
|
||||||
|
|| (guac_keyboard.modifiers.meta);
|
||||||
|
|
||||||
|
if (keypress_unlikely && e.keyIdentifier)
|
||||||
|
keysym = keysym || keysym_from_key_identifier(
|
||||||
|
guac_keyboard.modifiers.shift, e.keyIdentifier, location);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Press key if known
|
// Press key if known
|
||||||
if (keysym !== null) {
|
if (keysym !== null) {
|
||||||
|
Reference in New Issue
Block a user