mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-862: Handle adjacent keypress for unidentifiable keydown.
This commit is contained in:
@@ -68,12 +68,28 @@ Guacamole.Keyboard = function(element) {
|
|||||||
*/
|
*/
|
||||||
var KeyEvent = function() {
|
var KeyEvent = function() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to this key event.
|
||||||
|
*/
|
||||||
|
var key_event = this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An arbitrary timestamp in milliseconds, indicating this event's
|
* An arbitrary timestamp in milliseconds, indicating this event's
|
||||||
* position in time relative to other events.
|
* position in time relative to other events.
|
||||||
*/
|
*/
|
||||||
this.timestamp = new Date().getTime();
|
this.timestamp = new Date().getTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of milliseconds elapsed since this event was
|
||||||
|
* received.
|
||||||
|
*
|
||||||
|
* @return {Number} The number of milliseconds elapsed since this
|
||||||
|
* event was received.
|
||||||
|
*/
|
||||||
|
this.getAge = function() {
|
||||||
|
return new Date().getTime() - key_event.timestamp;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -675,6 +691,21 @@ Guacamole.Keyboard = function(element) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reinterpretation timeout handle returned via window.setTimeout() when
|
||||||
|
* future evaluation is needed, but the necessary event may not actually be
|
||||||
|
* generated.
|
||||||
|
*/
|
||||||
|
var reinterpret_timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules future reinterpretation of logged key events.
|
||||||
|
*/
|
||||||
|
function schedule_reinterpret() {
|
||||||
|
window.clearTimeout(reinterpret_timeout);
|
||||||
|
reinterpret_timeout = window.setTimeout(interpret_events, 100);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads through the event log, removing events from the head of the log
|
* Reads through the event log, removing events from the head of the log
|
||||||
* when the corresponding true key presses are known (or as known as they
|
* when the corresponding true key presses are known (or as known as they
|
||||||
@@ -693,14 +724,39 @@ Guacamole.Keyboard = function(element) {
|
|||||||
// Keydown event
|
// Keydown event
|
||||||
if (first instanceof KeydownEvent) {
|
if (first instanceof KeydownEvent) {
|
||||||
|
|
||||||
|
var keysym;
|
||||||
|
|
||||||
// If key is known from keyCode or DOM3 alone, use that
|
// If key is known from keyCode or DOM3 alone, use that
|
||||||
var keysym = keysym_from_key_identifier(first.key, first.location)
|
keysym = keysym_from_key_identifier(first.key, first.location)
|
||||||
|| keysym_from_keycode(first.keyCode, first.location);
|
|| keysym_from_keycode(first.keyCode, first.location);
|
||||||
if (keysym) {
|
if (keysym) {
|
||||||
eventLog.shift();
|
eventLog.shift();
|
||||||
return !press_key(keysym);
|
return !press_key(keysym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If keydown is immediately followed by a keypress, use the indicated character
|
||||||
|
var next = eventLog[1];
|
||||||
|
if (next && next instanceof KeypressEvent) {
|
||||||
|
|
||||||
|
keysym = keysym_from_charcode(next.charCode);
|
||||||
|
if (keysym) {
|
||||||
|
eventLog.shift();
|
||||||
|
return !press_key(keysym);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If keypress cannot be identified, then drop
|
||||||
|
eventLog.shift();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop event if completely old and uninterpretable
|
||||||
|
else if (first.getAge() > 100)
|
||||||
|
eventLog.shift();
|
||||||
|
|
||||||
|
// Lacking further information, pray for a future keypress event
|
||||||
|
else
|
||||||
|
schedule_reinterpret();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keyup event
|
// Keyup event
|
||||||
@@ -715,6 +771,9 @@ Guacamole.Keyboard = function(element) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop if keyup cannot be narrowed to a specific key
|
||||||
|
eventLog.shift();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump any other type of event (keypress by itself is invalid)
|
// Dump any other type of event (keypress by itself is invalid)
|
||||||
|
Reference in New Issue
Block a user