mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-352: Handle both "input" and "compositionend" events as sources of keys.
This commit is contained in:
@@ -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);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user