mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Allow user of API to decide whether keyboard events are canceled.
This commit is contained in:
@@ -60,6 +60,9 @@ Guacamole.Keyboard = function(element) {
|
||||
*
|
||||
* @event
|
||||
* @param {Number} keysym The keysym of the key being pressed.
|
||||
* @returns {Boolean} true if the originating event of this keypress should
|
||||
* be allowed through to the browser, false or undefined
|
||||
* otherwise.
|
||||
*/
|
||||
this.onkeydown = null;
|
||||
|
||||
@@ -69,6 +72,9 @@ Guacamole.Keyboard = function(element) {
|
||||
*
|
||||
* @event
|
||||
* @param {Number} keysym The keysym of the key being released.
|
||||
* @returns {Boolean} true if the originating event of this key release
|
||||
* should be allowed through to the browser, false or
|
||||
* undefined otherwise.
|
||||
*/
|
||||
this.onkeyup = null;
|
||||
|
||||
@@ -208,13 +214,15 @@ Guacamole.Keyboard = function(element) {
|
||||
// Sends a single keystroke over the network
|
||||
function sendKeyPressed(keysym) {
|
||||
if (keysym != null && guac_keyboard.onkeydown)
|
||||
guac_keyboard.onkeydown(keysym);
|
||||
return guac_keyboard.onkeydown(keysym) != false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Sends a single keystroke over the network
|
||||
function sendKeyReleased(keysym) {
|
||||
if (keysym != null && guac_keyboard.onkeyup)
|
||||
guac_keyboard.onkeyup(keysym);
|
||||
return guac_keyboard.onkeyup(keysym) != false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -269,11 +277,13 @@ Guacamole.Keyboard = function(element) {
|
||||
// Send key event here
|
||||
if (keySymSource == KEYDOWN) {
|
||||
|
||||
var returnValue = true;
|
||||
|
||||
if (keydownChar[keynum] != keysym) {
|
||||
|
||||
// Send event
|
||||
keydownChar[keynum] = keysym;
|
||||
sendKeyPressed(keysym);
|
||||
returnValue = sendKeyPressed(keysym);
|
||||
|
||||
// Clear old key repeat, if any.
|
||||
stopRepeat();
|
||||
@@ -283,7 +293,7 @@ Guacamole.Keyboard = function(element) {
|
||||
repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500);
|
||||
}
|
||||
|
||||
return false;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -302,6 +312,7 @@ Guacamole.Keyboard = function(element) {
|
||||
if (window.event) keynum = window.event.keyCode;
|
||||
else if (e.which) keynum = e.which;
|
||||
|
||||
var returnValue = true;
|
||||
var keysym = getKeySymFromCharCode(keynum);
|
||||
if (keysym && keydownChar[keynum] != keysym) {
|
||||
|
||||
@@ -316,13 +327,14 @@ Guacamole.Keyboard = function(element) {
|
||||
stopRepeat();
|
||||
|
||||
// Send key event
|
||||
sendKeyPressed(keysym);
|
||||
returnValue = sendKeyPressed(keysym);
|
||||
|
||||
// Start repeating (if not a modifier key) after a short delay
|
||||
repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500);
|
||||
}
|
||||
|
||||
return false;
|
||||
return returnValue;
|
||||
|
||||
};
|
||||
|
||||
// When key released
|
||||
@@ -352,9 +364,8 @@ Guacamole.Keyboard = function(element) {
|
||||
keydownChar[keynum] = null;
|
||||
|
||||
// Send release event
|
||||
sendKeyReleased(lastKeyDownChar);
|
||||
return sendKeyReleased(lastKeyDownChar);
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// When focus is lost, clear modifiers.
|
||||
|
Reference in New Issue
Block a user