Skip to content

Commit

Permalink
fix(lib): GUACAMOLE-520: Add mapping of Japanese IME keys
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMcAssey committed Feb 5, 2025
1 parent 20d57a8 commit 706b668
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var Guacamole = Guacamole || {};
* Provides cross-browser and cross-keyboard keyboard for a specific element.
* Browser and keyboard layout variation is abstracted away, providing events
* which represent keys as their corresponding X11 keysym.
*
*
* @constructor
* @param {Element|Document} [element]
* The Element to use to provide keyboard events. If omitted, at least one
Expand Down Expand Up @@ -62,7 +62,7 @@ Guacamole.Keyboard = function Keyboard(element) {
/**
* Fired whenever the user presses a key with the element associated
* with this Guacamole.Keyboard in focus.
*
*
* @event
* @param {!number} keysym
* The keysym of the key being pressed.
Expand All @@ -76,7 +76,7 @@ Guacamole.Keyboard = function Keyboard(element) {
/**
* Fired whenever the user releases a key with the element associated
* with this Guacamole.Keyboard in focus.
*
*
* @event
* @param {!number} keysym
* The keysym of the key being released.
Expand Down Expand Up @@ -158,7 +158,7 @@ Guacamole.Keyboard = function Keyboard(element) {
/**
* The JavaScript key code of the key pressed. For most events (keydown
* and keyup), this is a scancode-like value related to the position of
* the key on the US English "Qwerty" keyboard. For keypress events,
* the key on the US English "Qwerty" keyboard. For keypress events,
* this is the Unicode codepoint of the character that would be typed
* by the key pressed.
*
Expand All @@ -177,7 +177,7 @@ Guacamole.Keyboard = function Keyboard(element) {
/**
* The standard name of the key pressed, as defined at:
* http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
*
*
* @type {!string}
*/
this.key = orig && orig.key;
Expand All @@ -186,7 +186,7 @@ Guacamole.Keyboard = function Keyboard(element) {
* The location on the keyboard corresponding to the key pressed, as
* defined at:
* http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
*
*
* @type {!number}
*/
this.location = orig ? getEventLocation(orig) : 0;
Expand Down Expand Up @@ -471,7 +471,7 @@ Guacamole.Keyboard = function Keyboard(element) {
"CapsLock": [0xFFE5],
"Cancel": [0xFF69],
"Clear": [0xFF0B],
"Convert": [0xFF21],
"Convert": [0xFF23],
"Copy": [0xFD15],
"Crsel": [0xFD1C],
"CrSel": [0xFD1C],
Expand Down Expand Up @@ -538,6 +538,7 @@ Guacamole.Keyboard = function Keyboard(element) {
"Left": [0xFF51],
"Meta": [0xFFE7, 0xFFE7, 0xFFE8],
"ModeChange": [0xFF7E],
"NonConvert": [0xFF22],
"NumLock": [0xFF7F],
"PageDown": [0xFF56],
"PageUp": [0xFF55],
Expand All @@ -547,6 +548,7 @@ Guacamole.Keyboard = function Keyboard(element) {
"PrintScreen": [0xFF61],
"Redo": [0xFF66],
"Right": [0xFF53],
"Romaji": [0xFF24],
"RomanCharacters": null,
"Scroll": [0xFF14],
"Select": [0xFF60],
Expand Down Expand Up @@ -577,11 +579,11 @@ Guacamole.Keyboard = function Keyboard(element) {
0xFE03: true, // ISO Level 3 Shift (AltGr)
0xFFE1: true, // Left shift
0xFFE2: true, // Right shift
0xFFE3: true, // Left ctrl
0xFFE4: true, // Right ctrl
0xFFE3: true, // Left ctrl
0xFFE4: true, // Right ctrl
0xFFE5: true, // Caps Lock
0xFFE7: true, // Left meta
0xFFE8: true, // Right meta
0xFFE7: true, // Left meta
0xFFE8: true, // Right meta
0xFFE9: true, // Left alt
0xFFEA: true, // Right alt
0xFFEB: true, // Left super/hyper
Expand All @@ -594,11 +596,11 @@ Guacamole.Keyboard = function Keyboard(element) {
* @type {!Guacamole.Keyboard.ModifierState}
*/
this.modifiers = new Guacamole.Keyboard.ModifierState();

/**
* The state of every key, indexed by keysym. If a particular key is
* pressed, the value of pressed for that keysym will be true. If a key
* is not currently pressed, it will not be defined.
* is not currently pressed, it will not be defined.
*
* @type {!Object.<number, boolean>}
*/
Expand Down Expand Up @@ -658,7 +660,7 @@ Guacamole.Keyboard = function Keyboard(element) {
* Given an array of keysyms indexed by location, returns the keysym
* for the given location, or the keysym for the standard location if
* undefined.
*
*
* @private
* @param {number[]} keysyms
* An array of keysyms, where the index of the keysym in the array is
Expand Down Expand Up @@ -702,7 +704,7 @@ Guacamole.Keyboard = function Keyboard(element) {

var typedCharacter;

// If identifier is U+xxxx, decode Unicode character
// If identifier is U+xxxx, decode Unicode character
var unicodePrefixLocation = identifier.indexOf("U+");
if (unicodePrefixLocation >= 0) {
var hex = identifier.substring(unicodePrefixLocation+2);
Expand Down Expand Up @@ -804,7 +806,7 @@ Guacamole.Keyboard = function Keyboard(element) {
* repeat for the pressed key will start after a delay if that key is
* not a modifier. The return value of this function depends on the
* return value of the keydown event handler, if any.
*
*
* @param {number} keysym
* The keysym of the key to press.
*
Expand Down Expand Up @@ -851,15 +853,15 @@ Guacamole.Keyboard = function Keyboard(element) {

/**
* Marks a key as released, firing the keyup event if registered.
*
*
* @param {number} keysym
* The keysym of the key to release.
*/
this.release = function(keysym) {

// Only release if pressed
if (guac_keyboard.pressed[keysym]) {

// Mark key as released
delete guac_keyboard.pressed[keysym];
delete implicitlyPressed[keysym];
Expand Down Expand Up @@ -1054,7 +1056,7 @@ Guacamole.Keyboard = function Keyboard(element) {
* 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
* can be).
*
*
* @private
* @return {boolean}
* Whether the default action of the latest event should be prevented.
Expand Down Expand Up @@ -1106,8 +1108,8 @@ Guacamole.Keyboard = function Keyboard(element) {

// Release Ctrl+Alt if the keysym is printable
if (keysym <= 0xFF || (keysym & 0xFF000000) === 0x01000000) {
guac_keyboard.release(0xFFE3); // Left ctrl
guac_keyboard.release(0xFFE4); // Right ctrl
guac_keyboard.release(0xFFE3); // Left ctrl
guac_keyboard.release(0xFFE4); // Right ctrl
guac_keyboard.release(0xFFE9); // Left alt
guac_keyboard.release(0xFFEA); // Right alt
}
Expand All @@ -1119,7 +1121,7 @@ Guacamole.Keyboard = function Keyboard(element) {
* and returning that event. If no events can be interpreted, due to a
* total lack of events or the need for more events, null is returned. Any
* interpreted events are automatically removed from the log.
*
*
* @private
* @return {KeyEvent}
* The first key event in the log, if it can be interpreted, or null
Expand Down Expand Up @@ -1455,28 +1457,28 @@ Guacamole.Keyboard._nextID = 0;
* @constructor
*/
Guacamole.Keyboard.ModifierState = function() {

/**
* Whether shift is currently pressed.
*
* @type {!boolean}
*/
this.shift = false;

/**
* Whether ctrl is currently pressed.
*
* @type {!boolean}
*/
this.ctrl = false;

/**
* Whether alt is currently pressed.
*
* @type {!boolean}
*/
this.alt = false;

/**
* Whether meta (apple key) is currently pressed.
*
Expand All @@ -1495,15 +1497,15 @@ Guacamole.Keyboard.ModifierState = function() {

/**
* Returns the modifier state applicable to the keyboard event given.
*
*
* @param {!KeyboardEvent} e
* The keyboard event to read.
*
* @returns {!Guacamole.Keyboard.ModifierState}
* The current state of keyboard modifiers.
*/
Guacamole.Keyboard.ModifierState.fromKeyboardEvent = function(e) {

var state = new Guacamole.Keyboard.ModifierState();

// Assign states from old flags
Expand All @@ -1521,5 +1523,5 @@ Guacamole.Keyboard.ModifierState.fromKeyboardEvent = function(e) {
}

return state;

};

0 comments on commit 706b668

Please sign in to comment.