mirror of
https://git.proxmox.com/git/mirror_novnc
synced 2025-08-05 17:23:37 +00:00
Simplify keyboard event API
No need for an object for three static fields.
This commit is contained in:
parent
94f5cf05f3
commit
d0703d1bde
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user