From 3ee73d835c3a3ac8b275fea7220aa7ee1fa6ab6a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 17 Dec 2017 21:09:15 -0800 Subject: [PATCH] GUACAMOLE-352: Handle both "input" and "compositionend" events as sources of keys. --- .../src/main/webapp/modules/Keyboard.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js index 0480d4dd0..42020c7c2 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -826,6 +826,30 @@ Guacamole.Keyboard = function(element) { }; + /** + * Presses and releases the keys necessary to type the given string of + * text. + * + * @param {String} str + * The string to type. + */ + this.type = function type(str) { + + // Press/release the key corresponding to each character in the string + for (var i = 0; i < str.length; i++) { + + // Determine keysym of current character + var codepoint = str.codePointAt ? str.codePointAt(i) : str.charCodeAt(i); + var keysym = keysym_from_charcode(codepoint); + + // Press and release key for current character + guac_keyboard.press(keysym); + guac_keyboard.release(keysym); + + } + + }; + /** * Resets the state of this keyboard, releasing all keys, and firing keyup * events for each released key. @@ -1183,6 +1207,30 @@ Guacamole.Keyboard = function(element) { }, true); + // Automatically type text entered into the wrapped element + element.addEventListener("input", function(e) { + + // Only intercept if handler set + if (!guac_keyboard.onkeydown && !guac_keyboard.onkeyup) return; + + // Type all content written + if (e.data) + guac_keyboard.type(e.data); + + }, false); + + // Automatically type the result of composed characters/text + element.addEventListener("compositionend", function(e) { + + // Only intercept if handler set + if (!guac_keyboard.onkeydown && !guac_keyboard.onkeyup) return; + + // Type all content written + if (e.data) + guac_keyboard.type(e.data); + + }, false); + }; /**