diff options
author | Pierre Ossman <ossman@cendio.se> | 2017-01-26 18:09:40 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2017-05-04 12:13:47 +0200 |
commit | d0703d1bdebe610261bc492e2c23877d359e5eb3 (patch) | |
tree | 7f2deadbd22c7011313b7a80927a094d769c0cd7 | |
parent | 94f5cf05f37191ec028781bd486fbf22a460e515 (diff) | |
download | novnc-d0703d1bdebe610261bc492e2c23877d359e5eb3.tar.gz |
Simplify keyboard event API
No need for an object for three static fields.
-rw-r--r-- | core/input/devices.js | 8 | ||||
-rw-r--r-- | core/rfb.js | 7 | ||||
-rw-r--r-- | tests/input.html | 6 | ||||
-rw-r--r-- | tests/test.rfb.js | 8 |
4 files changed, 13 insertions, 16 deletions
diff --git a/core/input/devices.js b/core/input/devices.js index c68966b..c92c6a3 100644 --- a/core/input/devices.js +++ b/core/input/devices.js @@ -47,10 +47,10 @@ Keyboard.prototype = { // private methods _handleRfbEvent: function (e) { - if (this._onKeyPress) { - Log.Debug("onKeyPress " + (e.type == 'keydown' ? "down" : "up") + + if (this._onKeyEvent) { + Log.Debug("onKeyEvent " + (e.type == 'keydown' ? "down" : "up") + ", keysym: " + e.keysym); - this._onKeyPress(e); + this._onKeyEvent(e.keysym, e.code, e.type == 'keydown'); } }, @@ -138,7 +138,7 @@ make_properties(Keyboard, [ ['target', 'wo', 'dom'], // DOM element that captures keyboard input ['focused', 'rw', 'bool'], // Capture and send key events - ['onKeyPress', 'rw', 'func'] // Handler for key press/release + ['onKeyEvent', 'rw', 'func'] // Handler for key press/release ]); const Mouse = function (defaults) { diff --git a/core/rfb.js b/core/rfb.js index 7f55123..46b3158 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -200,7 +200,7 @@ export default function RFB(defaults) { } this._keyboard = new Keyboard({target: this._focusContainer, - onKeyPress: this._handleKeyPress.bind(this)}); + onKeyEvent: this._handleKeyEvent.bind(this)}); this._mouse = new Mouse({target: this._target, onMouseButton: this._handleMouseButton.bind(this), @@ -664,9 +664,8 @@ RFB.prototype = { } }, - _handleKeyPress: function (keyevent) { - var down = (keyevent.type == 'keydown'); - this.sendKey(keyevent.keysym, keyevent.code, down); + _handleKeyEvent: function (keysym, code, down) { + this.sendKey(keysym, code, down); }, _handleMouseButton: function (x, y, down, bmask) { diff --git a/tests/input.html b/tests/input.html index cd31f7e..aee9e76 100644 --- a/tests/input.html +++ b/tests/input.html @@ -62,9 +62,9 @@ //console.log(msg); } - function rfbKeyPress(keysym, down) { + function rfbKeyEvent(keysym, code, down) { var d = down ? "down" : " up "; - var msg = "RFB keypress " + d + " keysym: " + keysym; + var msg = "RFB key event " + d + " keysym: " + keysym + " code: " + code; message(msg); } function rawKey(e) { @@ -103,7 +103,7 @@ window.onload = function() { canvas = new Display({'target' : document.getElementById('canvas')}); keyboard = new Keyboard({'target': document, - 'onKeyPress': rfbKeyPress}); + 'onKeyEvent': rfbKeyEvent}); document.addEventListener('keypress', rawKey); document.addEventListener('keydown', rawKey); document.addEventListener('keyup', rawKey); diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 70504a5..4f5267f 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -2026,17 +2026,15 @@ describe('Remote Frame Buffer Protocol Client', function() { it('should send a key message on a key press', function () { var keyevent = {}; - keyevent.type = 'keydown'; - keyevent.keysym = 1234; - client._keyboard._onKeyPress(keyevent); + client._keyboard._onKeyEvent(0x41, 'KeyA', true); var key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}}; - RFB.messages.keyEvent(key_msg, 1234, 1); + RFB.messages.keyEvent(key_msg, 0x41, 1); expect(client._sock).to.have.sent(key_msg._sQ); }); it('should not send messages in view-only mode', function () { client._view_only = true; - client._keyboard._onKeyPress(1234, 1); + client._keyboard._onKeyEvent('a', 'KeyA', true); expect(client._sock.flush).to.not.have.been.called; }); }); |