Remove keysym names from keysymdef.js

They were incomplete and turned off in most cases so they served
little use besides adding complexity.
This commit is contained in:
Pierre Ossman 2017-01-24 12:07:26 +01:00
parent 9076defaca
commit 524d67f283
10 changed files with 174 additions and 198 deletions

View File

@ -1519,7 +1519,7 @@ const UI = {
UI.rfb.sendKey(KeyTable.XK_BackSpace); UI.rfb.sendKey(KeyTable.XK_BackSpace);
} }
for (i = newLen - inputs; i < newLen; i++) { for (i = newLen - inputs; i < newLen; i++) {
UI.rfb.sendKey(keysyms.fromUnicode(newValue.charCodeAt(i)).keysym); UI.rfb.sendKey(keysyms.lookup(newValue.charCodeAt(i)));
} }
// Control the text content length in the keyboardinput element // Control the text content length in the keyboardinput element

View File

@ -51,7 +51,7 @@ Keyboard.prototype = {
_handleRfbEvent: function (e) { _handleRfbEvent: function (e) {
if (this._onKeyPress) { if (this._onKeyPress) {
Log.Debug("onKeyPress " + (e.type == 'keydown' ? "down" : "up") + Log.Debug("onKeyPress " + (e.type == 'keydown' ? "down" : "up") +
", keysym: " + e.keysym.keysym + "(" + e.keysym.keyname + ")"); ", keysym: " + e.keysym);
this._onKeyPress(e); this._onKeyPress(e);
} }
}, },

File diff suppressed because one or more lines are too long

View File

@ -93,7 +93,7 @@ export function ModifierSync(charModifier) {
function sync(evt, keysym) { function sync(evt, keysym) {
var result = []; var result = [];
function syncKey(keysym) { function syncKey(keysym) {
return {keysym: keysyms.lookup(keysym), type: state[keysym] ? 'keydown' : 'keyup'}; return {keysym: keysym, type: state[keysym] ? 'keydown' : 'keyup'};
} }
if (evt.ctrlKey !== undefined && if (evt.ctrlKey !== undefined &&
@ -124,8 +124,7 @@ export function ModifierSync(charModifier) {
return result; return result;
} }
function syncKeyEvent(evt, down) { function syncKeyEvent(evt, down) {
var obj = getKeysym(evt); var keysym = getKeysym(evt);
var keysym = obj ? obj.keysym : null;
// first, apply the event itself, if relevant // first, apply the event itself, if relevant
if (keysym !== null && state[keysym] !== undefined) { if (keysym !== null && state[keysym] !== undefined) {
@ -177,17 +176,17 @@ export function getKeysym(evt){
codepoint = evt.keyCode; codepoint = evt.keyCode;
} }
if (codepoint) { if (codepoint) {
return keysyms.fromUnicode(substituteCodepoint(codepoint)); return keysyms.lookup(substituteCodepoint(codepoint));
} }
// we could check evt.key here. // we could check evt.key here.
// Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list, // Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list,
// so we "just" need to map them to keysym, but AFAIK this is only available in IE10, which also provides evt.key // so we "just" need to map them to keysym, but AFAIK this is only available in IE10, which also provides evt.key
// so we don't *need* it yet // so we don't *need* it yet
if (evt.keyCode) { if (evt.keyCode) {
return keysyms.lookup(keysymFromKeyCode(evt.keyCode, evt.shiftKey)); return keysymFromKeyCode(evt.keyCode, evt.shiftKey);
} }
if (evt.which) { if (evt.which) {
return keysyms.lookup(keysymFromKeyCode(evt.which, evt.shiftKey)); return keysymFromKeyCode(evt.which, evt.shiftKey);
} }
return null; return null;
} }
@ -453,7 +452,7 @@ export function KeyEventDecoder (modifierState, next) {
if (active && keysym) { if (active && keysym) {
var isCharModifier = false; var isCharModifier = false;
for (var i = 0; i < active.length; ++i) { for (var i = 0; i < active.length; ++i) {
if (active[i] === keysym.keysym) { if (active[i] === keysym) {
isCharModifier = true; isCharModifier = true;
} }
} }
@ -527,7 +526,7 @@ export function VerifyCharModifier (next) {
// Firefox sends keypress even when no char is generated. // Firefox sends keypress even when no char is generated.
// so, if keypress keysym is the same as we'd have guessed from keydown, // so, if keypress keysym is the same as we'd have guessed from keydown,
// the modifier didn't have any effect, and should not be escaped // the modifier didn't have any effect, and should not be escaped
if (queue[0].escape && (!cur.keysym || cur.keysym.keysym !== queue[0].keysym.keysym)) { if (queue[0].escape && (!cur.keysym || cur.keysym !== queue[0].keysym)) {
cur.escape = queue[0].escape; cur.escape = queue[0].escape;
} }
cur.keysym = queue[0].keysym; cur.keysym = queue[0].keysym;
@ -570,7 +569,7 @@ export function TrackKeyState (next) {
if (evt.keysym) { if (evt.keysym) {
// make sure last event contains this keysym (a single "logical" keyevent // make sure last event contains this keysym (a single "logical" keyevent
// can cause multiple key events to be sent to the VNC server) // can cause multiple key events to be sent to the VNC server)
last.keysyms[evt.keysym.keysym] = evt.keysym; last.keysyms[evt.keysym] = evt.keysym;
last.ignoreKeyPress = true; last.ignoreKeyPress = true;
next(evt); next(evt);
} }
@ -587,7 +586,7 @@ export function TrackKeyState (next) {
// If we didn't expect a keypress, and already sent a keydown to the VNC server // If we didn't expect a keypress, and already sent a keydown to the VNC server
// based on the keydown, make sure to skip this event. // based on the keydown, make sure to skip this event.
if (evt.keysym && !last.ignoreKeyPress) { if (evt.keysym && !last.ignoreKeyPress) {
last.keysyms[evt.keysym.keysym] = evt.keysym; last.keysyms[evt.keysym] = evt.keysym;
evt.type = 'keydown'; evt.type = 'keydown';
next(evt); next(evt);
} }
@ -646,14 +645,14 @@ export function EscapeModifiers (next) {
} }
// undo modifiers // undo modifiers
for (var i = 0; i < evt.escape.length; ++i) { for (var i = 0; i < evt.escape.length; ++i) {
next({type: 'keyup', keyId: 0, keysym: keysyms.lookup(evt.escape[i])}); next({type: 'keyup', keyId: 0, keysym: evt.escape[i]});
} }
// send the character event // send the character event
next(evt); next(evt);
// redo modifiers // redo modifiers
/* jshint shadow: true */ /* jshint shadow: true */
for (var i = 0; i < evt.escape.length; ++i) { for (var i = 0; i < evt.escape.length; ++i) {
next({type: 'keydown', keyId: 0, keysym: keysyms.lookup(evt.escape[i])}); next({type: 'keydown', keyId: 0, keysym: evt.escape[i]});
} }
/* jshint shadow: false */ /* jshint shadow: false */
}; };

View File

@ -659,7 +659,7 @@ RFB.prototype = {
Log.Error('Unable to find a xt scancode for code = ' + keyevent.code); Log.Error('Unable to find a xt scancode for code = ' + keyevent.code);
} }
} else { } else {
keysym = keyevent.keysym.keysym; keysym = keyevent.keysym;
RFB.messages.keyEvent(this._sock, keysym, down); RFB.messages.keyEvent(this._sock, keysym, down);
} }
}, },

View File

@ -63,11 +63,7 @@
function rfbKeyPress(keysym, down) { function rfbKeyPress(keysym, down) {
var d = down ? "down" : " up "; var d = down ? "down" : " up ";
var key = keysyms.lookup(keysym);
var msg = "RFB keypress " + d + " keysym: " + keysym; var msg = "RFB keypress " + d + " keysym: " + keysym;
if (key && key.keyname) {
msg += " key name: " + key.keyname;
}
message(msg); message(msg);
} }
function rawKey(e) { function rawKey(e) {

View File

@ -23,29 +23,29 @@ describe('Helpers', function() {
}); });
}); });
describe('keysyms.fromUnicode', function() { describe('keysyms.lookup', function() {
it('should map ASCII characters to keysyms', function() { it('should map ASCII characters to keysyms', function() {
expect(keysyms.fromUnicode('a'.charCodeAt())).to.have.property('keysym', 0x61); expect(keysyms.lookup('a'.charCodeAt())).to.be.equal(0x61);
expect(keysyms.fromUnicode('A'.charCodeAt())).to.have.property('keysym', 0x41); expect(keysyms.lookup('A'.charCodeAt())).to.be.equal(0x41);
}); });
it('should map Latin-1 characters to keysyms', function() { it('should map Latin-1 characters to keysyms', function() {
expect(keysyms.fromUnicode('ø'.charCodeAt())).to.have.property('keysym', 0xf8); expect(keysyms.lookup('ø'.charCodeAt())).to.be.equal(0xf8);
expect(keysyms.fromUnicode('é'.charCodeAt())).to.have.property('keysym', 0xe9); expect(keysyms.lookup('é'.charCodeAt())).to.be.equal(0xe9);
}); });
it('should map characters that are in Windows-1252 but not in Latin-1 to keysyms', function() { it('should map characters that are in Windows-1252 but not in Latin-1 to keysyms', function() {
expect(keysyms.fromUnicode('Š'.charCodeAt())).to.have.property('keysym', 0x01a9); expect(keysyms.lookup('Š'.charCodeAt())).to.be.equal(0x01a9);
}); });
it('should map characters which aren\'t in Latin1 *or* Windows-1252 to keysyms', function() { it('should map characters which aren\'t in Latin1 *or* Windows-1252 to keysyms', function() {
expect(keysyms.fromUnicode('ŵ'.charCodeAt())).to.have.property('keysym', 0x1000175); expect(keysyms.lookup('ŵ'.charCodeAt())).to.be.equal(0x1000175);
}); });
it('should map unknown codepoints to the Unicode range', function() { it('should map unknown codepoints to the Unicode range', function() {
expect(keysyms.fromUnicode('\n'.charCodeAt())).to.have.property('keysym', 0x100000a); expect(keysyms.lookup('\n'.charCodeAt())).to.be.equal(0x100000a);
expect(keysyms.fromUnicode('\u262D'.charCodeAt())).to.have.property('keysym', 0x100262d); expect(keysyms.lookup('\u262D'.charCodeAt())).to.be.equal(0x100262d);
}); });
// This requires very recent versions of most browsers... skipping for now // This requires very recent versions of most browsers... skipping for now
it.skip('should map UCS-4 codepoints to the Unicode range', function() { it.skip('should map UCS-4 codepoints to the Unicode range', function() {
//expect(keysyms.fromUnicode('\u{1F686}'.codePointAt())).to.have.property('keysym', 0x101f686); //expect(keysyms.lookup('\u{1F686}'.codePointAt())).to.be.equal(0x101f686);
}); });
}); });
@ -81,23 +81,23 @@ describe('Helpers', function() {
describe('getKeysym', function() { describe('getKeysym', function() {
it('should prefer char', function() { it('should prefer char', function() {
expect(KeyboardUtil.getKeysym({char : 'a', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.have.property('keysym', 0x61); expect(KeyboardUtil.getKeysym({char : 'a', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal(0x61);
}); });
it('should use charCode if no char', function() { it('should use charCode if no char', function() {
expect(KeyboardUtil.getKeysym({char : '', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.have.property('keysym', 0x01a9); expect(KeyboardUtil.getKeysym({char : '', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal(0x01a9);
expect(KeyboardUtil.getKeysym({charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.have.property('keysym', 0x01a9); expect(KeyboardUtil.getKeysym({charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal(0x01a9);
expect(KeyboardUtil.getKeysym({char : 'hello', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.have.property('keysym', 0x01a9); expect(KeyboardUtil.getKeysym({char : 'hello', charCode: 'Š'.charCodeAt(), keyCode: 0x42, which: 0x43})).to.be.equal(0x01a9);
}); });
it('should use keyCode if no charCode', function() { it('should use keyCode if no charCode', function() {
expect(KeyboardUtil.getKeysym({keyCode: 0x42, which: 0x43, shiftKey: false})).to.have.property('keysym', 0x62); expect(KeyboardUtil.getKeysym({keyCode: 0x42, which: 0x43, shiftKey: false})).to.be.equal(0x62);
expect(KeyboardUtil.getKeysym({keyCode: 0x42, which: 0x43, shiftKey: true})).to.have.property('keysym', 0x42); expect(KeyboardUtil.getKeysym({keyCode: 0x42, which: 0x43, shiftKey: true})).to.be.equal(0x42);
}); });
it('should use which if no keyCode', function() { it('should use which if no keyCode', function() {
expect(KeyboardUtil.getKeysym({which: 0x43, shiftKey: false})).to.have.property('keysym', 0x63); expect(KeyboardUtil.getKeysym({which: 0x43, shiftKey: false})).to.be.equal(0x63);
expect(KeyboardUtil.getKeysym({which: 0x43, shiftKey: true})).to.have.property('keysym', 0x43); expect(KeyboardUtil.getKeysym({which: 0x43, shiftKey: true})).to.be.equal(0x43);
}); });
it('should substitute where applicable', function() { it('should substitute where applicable', function() {
expect(KeyboardUtil.getKeysym({char : 'Ș'})).to.have.property('keysym', 0x1aa); expect(KeyboardUtil.getKeysym({char : 'Ș'})).to.be.equal(0x1aa);
}); });
}); });
@ -151,13 +151,13 @@ describe('Helpers', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
ctrlKey: true, ctrlKey: true,
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe3), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xffe3, type: 'keydown'}]);
}); });
it('should sync if modifier is suddenly up', function() { it('should sync if modifier is suddenly up', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
ctrlKey: false ctrlKey: false
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe3), type: 'keyup'}]); })).to.be.deep.equal([{keysym: 0xffe3, type: 'keyup'}]);
}); });
}); });
describe('Toggle Alt', function() { describe('Toggle Alt', function() {
@ -166,13 +166,13 @@ describe('Helpers', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
altKey: true, altKey: true,
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe9), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xffe9, type: 'keydown'}]);
}); });
it('should sync if modifier is suddenly up', function() { it('should sync if modifier is suddenly up', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
altKey: false altKey: false
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe9), type: 'keyup'}]); })).to.be.deep.equal([{keysym: 0xffe9, type: 'keyup'}]);
}); });
}); });
describe('Toggle AltGr', function() { describe('Toggle AltGr', function() {
@ -181,13 +181,13 @@ describe('Helpers', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
altGraphKey: true, altGraphKey: true,
})).to.be.deep.equal([{keysym: keysyms.lookup(0xfe03), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xfe03, type: 'keydown'}]);
}); });
it('should sync if modifier is suddenly up', function() { it('should sync if modifier is suddenly up', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
altGraphKey: false altGraphKey: false
})).to.be.deep.equal([{keysym: keysyms.lookup(0xfe03), type: 'keyup'}]); })).to.be.deep.equal([{keysym: 0xfe03, type: 'keyup'}]);
}); });
}); });
describe('Toggle Shift', function() { describe('Toggle Shift', function() {
@ -196,13 +196,13 @@ describe('Helpers', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
shiftKey: true, shiftKey: true,
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe1), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xffe1, type: 'keydown'}]);
}); });
it('should sync if modifier is suddenly up', function() { it('should sync if modifier is suddenly up', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
shiftKey: false shiftKey: false
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe1), type: 'keyup'}]); })).to.be.deep.equal([{keysym: 0xffe1, type: 'keyup'}]);
}); });
}); });
describe('Toggle Meta', function() { describe('Toggle Meta', function() {
@ -211,13 +211,13 @@ describe('Helpers', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
metaKey: true, metaKey: true,
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe7), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xffe7, type: 'keydown'}]);
}); });
it('should sync if modifier is suddenly up', function() { it('should sync if modifier is suddenly up', function() {
expect(sync.keydown({ expect(sync.keydown({
keyCode: 0x41, keyCode: 0x41,
metaKey: false metaKey: false
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe7), type: 'keyup'}]); })).to.be.deep.equal([{keysym: 0xffe7, type: 'keyup'}]);
}); });
}); });
describe('Modifier keyevents', function() { describe('Modifier keyevents', function() {
@ -245,14 +245,14 @@ describe('Helpers', function() {
expect(KeyboardUtil.ModifierSync().keydown({ expect(KeyboardUtil.ModifierSync().keydown({
keyCode: 0x11, keyCode: 0x11,
altKey: true altKey: true
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe9), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xffe9, type: 'keydown'}]);
}) })
}); });
describe('sync modifiers on non-key events', function() { describe('sync modifiers on non-key events', function() {
it('should generate sync events when receiving non-keyboard events', function() { it('should generate sync events when receiving non-keyboard events', function() {
expect(KeyboardUtil.ModifierSync().syncAny({ expect(KeyboardUtil.ModifierSync().syncAny({
altKey: true altKey: true
})).to.be.deep.equal([{keysym: keysyms.lookup(0xffe9), type: 'keydown'}]); })).to.be.deep.equal([{keysym: 0xffe9, type: 'keydown'}]);
}); });
}); });
describe('do not treat shift as a modifier key', function() { describe('do not treat shift as a modifier key', function() {

View File

@ -16,7 +16,7 @@ describe('Key Event Pipeline Stages', function() {
}); });
it('should pass the right keysym through', function(done) { it('should pass the right keysym through', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt.keysym).to.be.deep.equal(keysyms.lookup(0x61)); expect(evt.keysym).to.be.deep.equal(0x61);
done(); done();
}).keypress({keyCode: 0x41}); }).keypress({keyCode: 0x41});
}); });
@ -39,11 +39,11 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
switch (count) { switch (count) {
case 0: // fake a ctrl keydown case 0: // fake a ctrl keydown
expect(evt).to.be.deep.equal({keysym: keysyms.lookup(0xffe3), type: 'keydown'}); expect(evt).to.be.deep.equal({keysym: 0xffe3, type: 'keydown'});
++count; ++count;
break; break;
case 1: case 1:
expect(evt).to.be.deep.equal({keyId: 0x41, type: 'keydown', keysym: keysyms.lookup(0x61)}); expect(evt).to.be.deep.equal({keyId: 0x41, type: 'keydown', keysym: 0x61});
done(); done();
break; break;
} }
@ -57,13 +57,13 @@ describe('Key Event Pipeline Stages', function() {
}); });
it('should forward keyup events with the right type', function(done) { it('should forward keyup events with the right type', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt).to.be.deep.equal({keyId: 0x41, keysym: keysyms.lookup(0x61), type: 'keyup'}); expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keyup'});
done(); done();
}).keyup({keyCode: 0x41}); }).keyup({keyCode: 0x41});
}); });
it('should forward keypress events with the right type', function(done) { it('should forward keypress events with the right type', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt).to.be.deep.equal({keyId: 0x41, keysym: keysyms.lookup(0x61), type: 'keypress'}); expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keypress'});
done(); done();
}).keypress({keyCode: 0x41}); }).keypress({keyCode: 0x41});
}); });
@ -72,7 +72,7 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync([0xfe03]), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync([0xfe03]), function(evt) {
switch (count) { switch (count) {
case 0: // fake altgr case 0: // fake altgr
expect(evt).to.be.deep.equal({keysym: keysyms.lookup(0xfe03), type: 'keydown'}); expect(evt).to.be.deep.equal({keysym: 0xfe03, type: 'keydown'});
++count; ++count;
break; break;
case 1: // stall before processing the 'a' keydown case 1: // stall before processing the 'a' keydown
@ -83,7 +83,7 @@ describe('Key Event Pipeline Stages', function() {
expect(evt).to.be.deep.equal({ expect(evt).to.be.deep.equal({
type: 'keydown', type: 'keydown',
keyId: 0x41, keyId: 0x41,
keysym: keysyms.lookup(0x61) keysym: 0x61
}); });
done(); done();
@ -197,7 +197,7 @@ describe('Key Event Pipeline Stages', function() {
expect(evt).to.be.deep.equal({ expect(evt).to.be.deep.equal({
type: 'keypress', type: 'keypress',
keyId: 'A'.charCodeAt(), keyId: 'A'.charCodeAt(),
keysym: keysyms.lookup('a'.charCodeAt()), keysym: 'a'.charCodeAt(),
escape: [0xfe03] escape: [0xfe03]
}); });
done(); done();
@ -220,7 +220,7 @@ describe('Key Event Pipeline Stages', function() {
expect(evt).to.be.deep.equal({ expect(evt).to.be.deep.equal({
type: 'keypress', type: 'keypress',
keyId: 'A'.charCodeAt(), keyId: 'A'.charCodeAt(),
keysym: keysyms.lookup('a'.charCodeAt()), keysym: 'a'.charCodeAt(),
escape: [0xffe9, 0xffe3] escape: [0xffe9, 0xffe3]
}); });
done(); done();
@ -252,7 +252,7 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
switch (times_called++) { switch (times_called++) {
case 1: case 1:
expect(evt).to.be.deep.equal({keyId: 0x41, keysym: keysyms.lookup(0x61), type: 'keydown'}); expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keydown'});
break; break;
} }
}).keydown({keyCode: 0x41, ctrlKey: true}); }).keydown({keyCode: 0x41, ctrlKey: true});
@ -263,7 +263,7 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync([0xfe03]), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync([0xfe03]), function(evt) {
switch (times_called++) { switch (times_called++) {
case 2: case 2:
expect(evt).to.be.deep.equal({keyId: 0x41, keysym: keysyms.lookup(0x61), type: 'keydown'}); expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keydown'});
break; break;
} }
}).keydown({keyCode: 0x41, altGraphKey: true}); }).keydown({keyCode: 0x41, altGraphKey: true});
@ -271,21 +271,21 @@ describe('Key Event Pipeline Stages', function() {
}); });
it('should not remove keysym from keydown if key is noncharacter', function() { it('should not remove keysym from keydown if key is noncharacter', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt, 'bacobjpace').to.be.deep.equal({keyId: 0x09, keysym: keysyms.lookup(0xff09), type: 'keydown'}); expect(evt, 'bacobjpace').to.be.deep.equal({keyId: 0x09, keysym: 0xff09, type: 'keydown'});
}).keydown({keyCode: 0x09}); }).keydown({keyCode: 0x09});
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt, 'ctrl').to.be.deep.equal({keyId: 0x11, keysym: keysyms.lookup(0xffe3), type: 'keydown'}); expect(evt, 'ctrl').to.be.deep.equal({keyId: 0x11, keysym: 0xffe3, type: 'keydown'});
}).keydown({keyCode: 0x11}); }).keydown({keyCode: 0x11});
}); });
it('should never remove keysym from keypress', function() { it('should never remove keysym from keypress', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt).to.be.deep.equal({keyId: 0x41, keysym: keysyms.lookup(0x61), type: 'keypress'}); expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keypress'});
}).keypress({keyCode: 0x41}); }).keypress({keyCode: 0x41});
}); });
it('should never remove keysym from keyup', function() { it('should never remove keysym from keyup', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) { KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt).to.be.deep.equal({keyId: 0x41, keysym: keysyms.lookup(0x61), type: 'keyup'}); expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keyup'});
}).keyup({keyCode: 0x41}); }).keyup({keyCode: 0x41});
}); });
}); });
@ -296,31 +296,31 @@ describe('Key Event Pipeline Stages', function() {
describe('Verify that char modifiers are active', function() { describe('Verify that char modifiers are active', function() {
it('should pass keydown events through if there is no stall', function(done) { it('should pass keydown events through if there is no stall', function(done) {
var obj = KeyboardUtil.VerifyCharModifier(function(evt){ var obj = KeyboardUtil.VerifyCharModifier(function(evt){
expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x41)}); expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x41});
done(); done();
})({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x41)}); })({type: 'keydown', keyId: 0x41, keysym: 0x41});
}); });
it('should pass keyup events through if there is no stall', function(done) { it('should pass keyup events through if there is no stall', function(done) {
var obj = KeyboardUtil.VerifyCharModifier(function(evt){ var obj = KeyboardUtil.VerifyCharModifier(function(evt){
expect(evt).to.deep.equal({type: 'keyup', keyId: 0x41, keysym: keysyms.lookup(0x41)}); expect(evt).to.deep.equal({type: 'keyup', keyId: 0x41, keysym: 0x41});
done(); done();
})({type: 'keyup', keyId: 0x41, keysym: keysyms.lookup(0x41)}); })({type: 'keyup', keyId: 0x41, keysym: 0x41});
}); });
it('should pass keypress events through if there is no stall', function(done) { it('should pass keypress events through if there is no stall', function(done) {
var obj = KeyboardUtil.VerifyCharModifier(function(evt){ var obj = KeyboardUtil.VerifyCharModifier(function(evt){
expect(evt).to.deep.equal({type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x41)}); expect(evt).to.deep.equal({type: 'keypress', keyId: 0x41, keysym: 0x41});
done(); done();
})({type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x41)}); })({type: 'keypress', keyId: 0x41, keysym: 0x41});
}); });
it('should not pass stall events through', function(done){ it('should not pass stall events through', function(done){
var obj = KeyboardUtil.VerifyCharModifier(function(evt){ var obj = KeyboardUtil.VerifyCharModifier(function(evt){
// should only be called once, for the keydown // should only be called once, for the keydown
expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x41)}); expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x41});
done(); done();
}); });
obj({type: 'stall'}); obj({type: 'stall'});
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x41)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x41});
}); });
it('should merge keydown and keypress events if they come after a stall', function(done) { it('should merge keydown and keypress events if they come after a stall', function(done) {
var next_called = false; var next_called = false;
@ -328,13 +328,13 @@ describe('Key Event Pipeline Stages', function() {
// should only be called once, for the keydown // should only be called once, for the keydown
expect(next_called).to.be.false; expect(next_called).to.be.false;
next_called = true; next_called = true;
expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x44)}); expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x44});
done(); done();
}); });
obj({type: 'stall'}); obj({type: 'stall'});
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
obj({type: 'keypress', keyId: 0x43, keysym: keysyms.lookup(0x44)}); obj({type: 'keypress', keyId: 0x43, keysym: 0x44});
expect(next_called).to.be.false; expect(next_called).to.be.false;
}); });
it('should preserve modifier attribute when merging if keysyms differ', function(done) { it('should preserve modifier attribute when merging if keysyms differ', function(done) {
@ -343,13 +343,13 @@ describe('Key Event Pipeline Stages', function() {
// should only be called once, for the keydown // should only be called once, for the keydown
expect(next_called).to.be.false; expect(next_called).to.be.false;
next_called = true; next_called = true;
expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x44), escape: [0xffe3]}); expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x44, escape: [0xffe3]});
done(); done();
}); });
obj({type: 'stall'}); obj({type: 'stall'});
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
obj({type: 'keypress', keyId: 0x43, keysym: keysyms.lookup(0x44), escape: [0xffe3]}); obj({type: 'keypress', keyId: 0x43, keysym: 0x44, escape: [0xffe3]});
expect(next_called).to.be.false; expect(next_called).to.be.false;
}); });
it('should not preserve modifier attribute when merging if keysyms are the same', function() { it('should not preserve modifier attribute when merging if keysyms are the same', function() {
@ -358,18 +358,18 @@ describe('Key Event Pipeline Stages', function() {
}); });
obj({type: 'stall'}); obj({type: 'stall'});
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
obj({type: 'keypress', keyId: 0x43, keysym: keysyms.lookup(0x42), escape: [0xffe3]}); obj({type: 'keypress', keyId: 0x43, keysym: 0x42, escape: [0xffe3]});
}); });
it('should not merge keydown and keypress events if there is no stall', function(done) { it('should not merge keydown and keypress events if there is no stall', function(done) {
var times_called = 0; var times_called = 0;
var obj = KeyboardUtil.VerifyCharModifier(function(evt){ var obj = KeyboardUtil.VerifyCharModifier(function(evt){
switch(times_called) { switch(times_called) {
case 0: case 0:
expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42});
break; break;
case 1: case 1:
expect(evt).to.deep.equal({type: 'keypress', keyId: 0x43, keysym: keysyms.lookup(0x44)}); expect(evt).to.deep.equal({type: 'keypress', keyId: 0x43, keysym: 0x44});
done(); done();
break; break;
} }
@ -377,21 +377,21 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
}); });
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
obj({type: 'keypress', keyId: 0x43, keysym: keysyms.lookup(0x44)}); obj({type: 'keypress', keyId: 0x43, keysym: 0x44});
}); });
it('should not merge keydown and keypress events if separated by another event', function(done) { it('should not merge keydown and keypress events if separated by another event', function(done) {
var times_called = 0; var times_called = 0;
var obj = KeyboardUtil.VerifyCharModifier(function(evt){ var obj = KeyboardUtil.VerifyCharModifier(function(evt){
switch(times_called) { switch(times_called) {
case 0: case 0:
expect(evt,1).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); expect(evt,1).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42});
break; break;
case 1: case 1:
expect(evt,2).to.deep.equal({type: 'keyup', keyId: 0x43, keysym: keysyms.lookup(0x44)}); expect(evt,2).to.deep.equal({type: 'keyup', keyId: 0x43, keysym: 0x44});
break; break;
case 2: case 2:
expect(evt,3).to.deep.equal({type: 'keypress', keyId: 0x45, keysym: keysyms.lookup(0x46)}); expect(evt,3).to.deep.equal({type: 'keypress', keyId: 0x45, keysym: 0x46});
done(); done();
break; break;
} }
@ -400,9 +400,9 @@ describe('Key Event Pipeline Stages', function() {
}); });
obj({type: 'stall'}); obj({type: 'stall'});
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
obj({type: 'keyup', keyId: 0x43, keysym: keysyms.lookup(0x44)}); obj({type: 'keyup', keyId: 0x43, keysym: 0x44});
obj({type: 'keypress', keyId: 0x45, keysym: keysyms.lookup(0x46)}); obj({type: 'keypress', keyId: 0x45, keysym: 0x46});
}); });
}); });
@ -421,19 +421,19 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
} }
elem = null; elem = null;
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}; elem = {type: 'keydown', keyId: 0x41, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keyup', keyId: 0x41}; elem = {type: 'keyup', keyId: 0x41};
@ -449,19 +449,19 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
} }
elem = null; elem = null;
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x42)}; elem = {type: 'keypress', keyId: 0x41, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keyup', keyId: 0x41}; elem = {type: 'keyup', keyId: 0x41};
@ -478,23 +478,23 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
elem = null; elem = null;
} }
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x42)}; elem = {type: 'keypress', keyId: 0x41, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x43)}; elem = {type: 'keypress', keyId: 0x41, keysym: 0x43};
keysymsdown[keysyms.lookup(0x43).keysym] = true; keysymsdown[0x43] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keyup', keyId: 0x41}; elem = {type: 'keyup', keyId: 0x41};
@ -510,23 +510,23 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
elem = null; elem = null;
} }
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x42)}; elem = {type: 'keydown', keyId: 0, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x43)}; elem = {type: 'keydown', keyId: 0, keysym: 0x43};
keysymsdown[keysyms.lookup(0x43).keysym] = true; keysymsdown[0x43] = true;
obj(elem); obj(elem);
expect(times_called).to.be.equal(2); expect(times_called).to.be.equal(2);
expect(elem).to.be.null; expect(elem).to.be.null;
@ -546,23 +546,23 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
elem = null; elem = null;
} }
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x42)}; elem = {type: 'keydown', keyId: 0, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x42)}; elem = {type: 'keydown', keyId: 0, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(times_called).to.be.equal(2); expect(times_called).to.be.equal(2);
expect(elem).to.be.null; expect(elem).to.be.null;
@ -579,23 +579,23 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
elem = null; elem = null;
} }
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x42)}; elem = {type: 'keypress', keyId: 0x41, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keypress', keyId: 0x42, keysym: keysyms.lookup(0x43)}; elem = {type: 'keypress', keyId: 0x42, keysym: 0x43};
keysymsdown[keysyms.lookup(0x43).keysym] = true; keysymsdown[0x43] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keyup', keyId: 0x41}; elem = {type: 'keyup', keyId: 0x41};
@ -614,23 +614,23 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
elem = null; elem = null;
} }
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x42)}; elem = {type: 'keydown', keyId: 0, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0x42, keysym: keysyms.lookup(0x43)}; elem = {type: 'keydown', keyId: 0x42, keysym: 0x43};
keysymsdown[keysyms.lookup(0x43).keysym] = true; keysymsdown[0x43] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
expect(times_called).to.be.equal(2); expect(times_called).to.be.equal(2);
@ -650,23 +650,23 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
if (elem.type == 'keyup') { if (elem.type == 'keyup') {
expect(evt).to.have.property('keysym'); expect(evt).to.have.property('keysym');
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
delete keysymsdown[evt.keysym.keysym]; delete keysymsdown[evt.keysym];
} }
else { else {
expect(evt).to.be.deep.equal(elem); expect(evt).to.be.deep.equal(elem);
expect (keysymsdown[evt.keysym.keysym]).to.not.be.undefined; expect (keysymsdown[evt.keysym]).to.not.be.undefined;
elem = null; elem = null;
} }
}); });
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}; elem = {type: 'keydown', keyId: 0x41, keysym: 0x42};
keysymsdown[keysyms.lookup(0x42).keysym] = true; keysymsdown[0x42] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x43)}; elem = {type: 'keydown', keyId: 0, keysym: 0x43};
keysymsdown[keysyms.lookup(0x43).keysym] = true; keysymsdown[0x43] = true;
obj(elem); obj(elem);
expect(elem).to.be.null; expect(elem).to.be.null;
elem = {type: 'keyup', keyId: 0x41}; elem = {type: 'keyup', keyId: 0x41};
@ -686,14 +686,14 @@ describe('Key Event Pipeline Stages', function() {
expect(evt.type).to.be.equal('keydown'); expect(evt.type).to.be.equal('keydown');
break; break;
case 3: case 3:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x42, keysym: keysyms.lookup(0x62)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x42, keysym: 0x62});
break; break;
} }
}); });
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x61)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x61});
obj({type: 'keydown', keyId: 0x42, keysym: keysyms.lookup(0x62)}); obj({type: 'keydown', keyId: 0x42, keysym: 0x62});
obj({type: 'keydown', keyId: 0x43, keysym: keysyms.lookup(0x63)}); obj({type: 'keydown', keyId: 0x43, keysym: 0x63});
obj({type: 'keyup', keyId: 0x42}); obj({type: 'keyup', keyId: 0x42});
expect(times_called).to.equal(4); expect(times_called).to.equal(4);
}); });
@ -707,14 +707,14 @@ describe('Key Event Pipeline Stages', function() {
expect(evt.type).to.be.equal('keydown'); expect(evt.type).to.be.equal('keydown');
break; break;
case 3: case 3:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: keysyms.lookup(0x61)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0x61});
break; break;
} }
}); });
obj({type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x61)}); obj({type: 'keydown', keyId: 0, keysym: 0x61});
obj({type: 'keydown', keyId: 0, keysym: keysyms.lookup(0x62)}); obj({type: 'keydown', keyId: 0, keysym: 0x62});
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x63)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x63});
obj({type: 'keyup', keyId: 0x0}); obj({type: 'keyup', keyId: 0x0});
expect(times_called).to.equal(4); expect(times_called).to.equal(4);
}); });
@ -728,14 +728,14 @@ describe('Key Event Pipeline Stages', function() {
expect(evt.type).to.be.equal('keydown'); expect(evt.type).to.be.equal('keydown');
break; break;
case 3: case 3:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x44, keysym: keysyms.lookup(0x63)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x44, keysym: 0x63});
break; break;
} }
}); });
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x61)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x61});
obj({type: 'keydown', keyId: 0x42, keysym: keysyms.lookup(0x62)}); obj({type: 'keydown', keyId: 0x42, keysym: 0x62});
obj({type: 'keydown', keyId: 0x43, keysym: keysyms.lookup(0x63)}); obj({type: 'keydown', keyId: 0x43, keysym: 0x63});
obj({type: 'keyup', keyId: 0x44}); obj({type: 'keyup', keyId: 0x44});
expect(times_called).to.equal(4); expect(times_called).to.equal(4);
}); });
@ -747,9 +747,9 @@ describe('Key Event Pipeline Stages', function() {
++times_called; ++times_called;
}); });
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
expect(times_called).to.be.equal(1); expect(times_called).to.be.equal(1);
obj({type: 'keypress', keyId: 0x41, keysym: keysyms.lookup(0x43)}); obj({type: 'keypress', keyId: 0x41, keysym: 0x43});
}); });
}); });
describe('releaseAll', function() { describe('releaseAll', function() {
@ -766,15 +766,15 @@ describe('Key Event Pipeline Stages', function() {
var obj = KeyboardUtil.TrackKeyState(function(evt) { var obj = KeyboardUtil.TrackKeyState(function(evt) {
switch (times_called++) { switch (times_called++) {
case 2: case 2:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: keysyms.lookup(0x41)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0x41});
break; break;
case 3: case 3:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: keysyms.lookup(0x42)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0x42});
break; break;
} }
}); });
obj({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x41)}); obj({type: 'keydown', keyId: 0x41, keysym: 0x41});
obj({type: 'keydown', keyId: 0x42, keysym: keysyms.lookup(0x42)}); obj({type: 'keydown', keyId: 0x42, keysym: 0x42});
expect(times_called).to.be.equal(2); expect(times_called).to.be.equal(2);
obj({type: 'releaseall'}); obj({type: 'releaseall'});
expect(times_called).to.be.equal(4); expect(times_called).to.be.equal(4);
@ -792,8 +792,8 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.EscapeModifiers(function(evt) { KeyboardUtil.EscapeModifiers(function(evt) {
expect(times_called).to.be.equal(0); expect(times_called).to.be.equal(0);
++times_called; ++times_called;
expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42});
})({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42)}); })({type: 'keydown', keyId: 0x41, keysym: 0x42});
expect(times_called).to.be.equal(1); expect(times_called).to.be.equal(1);
}); });
it('should generate fake undo/redo events when a char modifier is down', function() { it('should generate fake undo/redo events when a char modifier is down', function() {
@ -801,22 +801,22 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.EscapeModifiers(function(evt) { KeyboardUtil.EscapeModifiers(function(evt) {
switch(times_called++) { switch(times_called++) {
case 0: case 0:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: keysyms.lookup(0xffe9)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0xffe9});
break; break;
case 1: case 1:
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: keysyms.lookup(0xffe3)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0xffe3});
break; break;
case 2: case 2:
expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42), escape: [0xffe9, 0xffe3]}); expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42, escape: [0xffe9, 0xffe3]});
break; break;
case 3: case 3:
expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0, keysym: keysyms.lookup(0xffe9)}); expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0, keysym: 0xffe9});
break; break;
case 4: case 4:
expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0, keysym: keysyms.lookup(0xffe3)}); expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0, keysym: 0xffe3});
break; break;
} }
})({type: 'keydown', keyId: 0x41, keysym: keysyms.lookup(0x42), escape: [0xffe9, 0xffe3]}); })({type: 'keydown', keyId: 0x41, keysym: 0x42, escape: [0xffe9, 0xffe3]});
expect(times_called).to.be.equal(5); expect(times_called).to.be.equal(5);
}); });
}); });
@ -826,8 +826,8 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.EscapeModifiers(function(evt) { KeyboardUtil.EscapeModifiers(function(evt) {
expect(times_called).to.be.equal(0); expect(times_called).to.be.equal(0);
++times_called; ++times_called;
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x41, keysym: keysyms.lookup(0x42), escape: [0xfe03]}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x41, keysym: 0x42, escape: [0xfe03]});
})({type: 'keyup', keyId: 0x41, keysym: keysyms.lookup(0x42), escape: [0xfe03]}); })({type: 'keyup', keyId: 0x41, keysym: 0x42, escape: [0xfe03]});
expect(times_called).to.be.equal(1); expect(times_called).to.be.equal(1);
}); });
it('should pass through when a char modifier is not down', function() { it('should pass through when a char modifier is not down', function() {
@ -835,8 +835,8 @@ describe('Key Event Pipeline Stages', function() {
KeyboardUtil.EscapeModifiers(function(evt) { KeyboardUtil.EscapeModifiers(function(evt) {
expect(times_called).to.be.equal(0); expect(times_called).to.be.equal(0);
++times_called; ++times_called;
expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x41, keysym: keysyms.lookup(0x42)}); expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x41, keysym: 0x42});
})({type: 'keyup', keyId: 0x41, keysym: keysyms.lookup(0x42)}); })({type: 'keyup', keyId: 0x41, keysym: 0x42});
expect(times_called).to.be.equal(1); expect(times_called).to.be.equal(1);
}); });
}); });

View File

@ -2017,8 +2017,7 @@ 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'; keyevent.type = 'keydown';
keyevent.keysym = {}; keyevent.keysym = 1234;
keyevent.keysym.keysym = 1234;
client._keyboard._onKeyPress(keyevent); 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, 1234, 1);

View File

@ -4,7 +4,6 @@
var fs = require('fs'); var fs = require('fs');
var show_help = process.argv.length === 2; var show_help = process.argv.length === 2;
var use_keynames = false;
var filename; var filename;
for (var i = 2; i < process.argv.length; ++i) { for (var i = 2; i < process.argv.length; ++i) {
@ -13,10 +12,6 @@ for (var i = 2; i < process.argv.length; ++i) {
case "-h": case "-h":
show_help = true; show_help = true;
break; break;
case "--debug-names":
case "-d":
use_keynames = true;
break;
case "--file": case "--file":
case "-f": case "-f":
default: default:
@ -33,14 +28,10 @@ if (show_help) {
console.log("Parses a *nix keysymdef.h to generate Unicode code point mappings"); console.log("Parses a *nix keysymdef.h to generate Unicode code point mappings");
console.log("Usage: node parse.js [options] filename:"); console.log("Usage: node parse.js [options] filename:");
console.log(" -h [ --help ] Produce this help message"); console.log(" -h [ --help ] Produce this help message");
console.log(" -d [ --debug-names ] Preserve keysym names for debugging (Increases file size by ~40KB)");
console.log(" filename The keysymdef.h file to parse"); console.log(" filename The keysymdef.h file to parse");
return; return;
} }
// Set this to false to omit key names from the generated keysymdef.js
// This reduces the file size by around 40kb, but may hinder debugging
var buf = fs.readFileSync(filename); var buf = fs.readFileSync(filename);
var str = buf.toString('utf8'); var str = buf.toString('utf8');
@ -48,7 +39,6 @@ var re = /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)
var arr = str.split('\n'); var arr = str.split('\n');
var keysyms = {};
var codepoints = {}; var codepoints = {};
for (var i = 0; i < arr.length; ++i) { for (var i = 0; i < arr.length; ++i) {
@ -58,8 +48,6 @@ for (var i = 0; i < arr.length; ++i) {
var keysym = parseInt(result[2], 16); var keysym = parseInt(result[2], 16);
var remainder = result[3]; var remainder = result[3];
keysyms[keysym] = keyname;
var unicodeRes = /U\+([0-9a-fA-F]+)/.exec(remainder); var unicodeRes = /U\+([0-9a-fA-F]+)/.exec(remainder);
if (unicodeRes) { if (unicodeRes) {
var unicode = parseInt(unicodeRes[1], 16); var unicode = parseInt(unicodeRes[1], 16);
@ -80,21 +68,18 @@ var out = "// This file describes mappings from Unicode codepoints to the keysym
"// (and optionally, key names) expected by the RFB protocol\n" + "// (and optionally, key names) expected by the RFB protocol\n" +
"// How this file was generated:\n" + "// How this file was generated:\n" +
"// " + process.argv.join(" ") + "\n" + "// " + process.argv.join(" ") + "\n" +
"var keynames = {keysyms};\n" + "\n" +
"var codepoints = {codepoints};\n" + "var codepoints = {codepoints};\n" +
"\n" + "\n" +
"function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }\n" +
"export default {\n" + "export default {\n" +
" fromUnicode : function(u) {\n" + " lookup : function(u) {\n" +
" var keysym = codepoints[u];\n" + " var keysym = codepoints[u];\n" +
" if (keysym === undefined) {\n" + " if (keysym === undefined) {\n" +
" keysym = 0x01000000 | u;\n" + " keysym = 0x01000000 | u;\n" +
" }\n" + " }\n" +
" return lookup(keysym);\n" + " return keysym;\n" +
" },\n" + " },\n" +
" lookup : lookup\n" +
"};\n"; "};\n";
out = out.replace('{keysyms}', use_keynames ? JSON.stringify(keysyms) : "null");
out = out.replace('{codepoints}', JSON.stringify(codepoints)); out = out.replace('{codepoints}', JSON.stringify(codepoints));
fs.writeFileSync("keysymdef.js", out); fs.writeFileSync("keysymdef.js", out);