mirror of
https://git.proxmox.com/git/mirror_novnc
synced 2025-08-09 23:26:21 +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
|
// private methods
|
||||||
|
|
||||||
_handleRfbEvent: function (e) {
|
_handleRfbEvent: function (e) {
|
||||||
if (this._onKeyPress) {
|
if (this._onKeyEvent) {
|
||||||
Log.Debug("onKeyPress " + (e.type == 'keydown' ? "down" : "up") +
|
Log.Debug("onKeyEvent " + (e.type == 'keydown' ? "down" : "up") +
|
||||||
", keysym: " + e.keysym);
|
", 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
|
['target', 'wo', 'dom'], // DOM element that captures keyboard input
|
||||||
['focused', 'rw', 'bool'], // Capture and send key events
|
['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) {
|
const Mouse = function (defaults) {
|
||||||
|
@ -200,7 +200,7 @@ export default function RFB(defaults) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._keyboard = new Keyboard({target: this._focusContainer,
|
this._keyboard = new Keyboard({target: this._focusContainer,
|
||||||
onKeyPress: this._handleKeyPress.bind(this)});
|
onKeyEvent: this._handleKeyEvent.bind(this)});
|
||||||
|
|
||||||
this._mouse = new Mouse({target: this._target,
|
this._mouse = new Mouse({target: this._target,
|
||||||
onMouseButton: this._handleMouseButton.bind(this),
|
onMouseButton: this._handleMouseButton.bind(this),
|
||||||
@ -664,9 +664,8 @@ RFB.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleKeyPress: function (keyevent) {
|
_handleKeyEvent: function (keysym, code, down) {
|
||||||
var down = (keyevent.type == 'keydown');
|
this.sendKey(keysym, code, down);
|
||||||
this.sendKey(keyevent.keysym, keyevent.code, down);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleMouseButton: function (x, y, down, bmask) {
|
_handleMouseButton: function (x, y, down, bmask) {
|
||||||
|
@ -62,9 +62,9 @@
|
|||||||
//console.log(msg);
|
//console.log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function rfbKeyPress(keysym, down) {
|
function rfbKeyEvent(keysym, code, down) {
|
||||||
var d = down ? "down" : " up ";
|
var d = down ? "down" : " up ";
|
||||||
var msg = "RFB keypress " + d + " keysym: " + keysym;
|
var msg = "RFB key event " + d + " keysym: " + keysym + " code: " + code;
|
||||||
message(msg);
|
message(msg);
|
||||||
}
|
}
|
||||||
function rawKey(e) {
|
function rawKey(e) {
|
||||||
@ -103,7 +103,7 @@
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
canvas = new Display({'target' : document.getElementById('canvas')});
|
canvas = new Display({'target' : document.getElementById('canvas')});
|
||||||
keyboard = new Keyboard({'target': document,
|
keyboard = new Keyboard({'target': document,
|
||||||
'onKeyPress': rfbKeyPress});
|
'onKeyEvent': rfbKeyEvent});
|
||||||
document.addEventListener('keypress', rawKey);
|
document.addEventListener('keypress', rawKey);
|
||||||
document.addEventListener('keydown', rawKey);
|
document.addEventListener('keydown', rawKey);
|
||||||
document.addEventListener('keyup', 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 () {
|
it('should send a key message on a key press', function () {
|
||||||
var keyevent = {};
|
var keyevent = {};
|
||||||
keyevent.type = 'keydown';
|
client._keyboard._onKeyEvent(0x41, 'KeyA', true);
|
||||||
keyevent.keysym = 1234;
|
|
||||||
client._keyboard._onKeyPress(keyevent);
|
|
||||||
var key_msg = {_sQ: new Uint8Array(8), _sQlen: 0, flush: function () {}};
|
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);
|
expect(client._sock).to.have.sent(key_msg._sQ);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not send messages in view-only mode', function () {
|
it('should not send messages in view-only mode', function () {
|
||||||
client._view_only = true;
|
client._view_only = true;
|
||||||
client._keyboard._onKeyPress(1234, 1);
|
client._keyboard._onKeyEvent('a', 'KeyA', true);
|
||||||
expect(client._sock.flush).to.not.have.been.called;
|
expect(client._sock.flush).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user