From 867daa98af7562403f3d7bd44efa3fdeb6732c6d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 16 Oct 2017 16:19:49 +0200 Subject: [PATCH] Restore handling of key events for virtual keyboard We broke handling of keydown/keyup when we moved the focus to the canvas, as events from our input element would then no longer be caught when they bubbled up to the document object (where we previously caught events). Restore the previous behaviour in a cleaner manner by creating a second Keyboard object to handle this extra input variant. --- app/ui.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/ui.js b/app/ui.js index 895f2ce..1e49a0e 100644 --- a/app/ui.js +++ b/app/ui.js @@ -17,6 +17,7 @@ import { isTouchDevice, browserSupportsCursorURIs as cursorURIsSupported } from import { setCapture, getPointerEvent } from '../core/util/events.js'; import KeyTable from "../core/input/keysym.js"; import keysyms from "../core/input/keysymdef.js"; +import Keyboard from "../core/input/keyboard.js"; import RFB from "../core/rfb.js"; import Display from "../core/display.js"; import * as WebUtil from "./webutil.js"; @@ -280,6 +281,9 @@ var UI = { document.getElementById("noVNC_keyboard_button") .addEventListener('click', UI.toggleVirtualKeyboard); + UI.touchKeyboard = new Keyboard({target: document.getElementById('noVNC_keyboardinput'), + onKeyEvent: UI.keyEvent}); + UI.touchKeyboard.grab(); document.getElementById("noVNC_keyboardinput") .addEventListener('input', UI.keyInput); document.getElementById("noVNC_keyboardinput") @@ -1506,6 +1510,12 @@ var UI = { UI.lastKeyboardinput = kbi.value; }, + keyEvent: function (keysym, code, down) { + if (!UI.rfb) return; + + UI.rfb.sendKey(keysym, code, down); + }, + // When normal keyboard events are left uncought, use the input events from // the keyboardinput element instead and generate the corresponding key events. // This code is required since some browsers on Android are inconsistent in -- 2.39.2