Simplify pressed key handling

Prefer avoid having the server simulate multiple key presses by
refusing to use multiple keysyms for the same physical key.
This commit is contained in:
Pierre Ossman
2017-01-27 12:26:55 +01:00
parent 9fce233d51
commit ae82053366
2 changed files with 45 additions and 60 deletions

View File

@@ -125,20 +125,25 @@ describe('Key Event Handling', function() {
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'b'}));
});
it('should send the same keysym for multiple presses', function() {
var count = 0;
var kbd = new Keyboard({
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
expect(down).to.be.equal(true);
count++;
}});
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'b'}));
expect(count).to.be.equal(2);
});
it('should do nothing on keyup events if no keys are down', function() {
var callback = sinon.spy();
var kbd = new Keyboard({onKeyEvent: callback});
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
expect(callback).to.not.have.been.called;
});
it('should send a key release for each key press with the same code', function() {
var callback = sinon.spy();
var kbd = new Keyboard({onKeyEvent: callback});
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'a'}));
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', key: 'b'}));
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA'}));
expect(callback.callCount).to.be.equal(4);
});
});
describe('Escape Modifiers', function() {