KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt).to.be.an.object;
done();
- }).keydown({keyCode: 0x41});
+ }).keydown({code: 'KeyA', keyCode: 0x41});
});
it('should pass the right keysym through', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
expect(evt.keysym).to.be.deep.equal(0x61);
done();
- }).keypress({keyCode: 0x41});
+ }).keypress({code: 'KeyA', keyCode: 0x41});
});
it('should pass the right keyid through', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.have.property('keyId', 0x41);
+ expect(evt).to.have.property('code', 'KeyA');
done();
- }).keydown({keyCode: 0x41});
+ }).keydown({code: 'KeyA', keyCode: 0x41});
});
it('should not sync modifiers on a keypress', function() {
// Firefox provides unreliable modifier state on keypress events
var count = 0;
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
++count;
- }).keypress({keyCode: 0x41, ctrlKey: true});
+ }).keypress({code: 'KeyA', keyCode: 0x41, ctrlKey: true});
expect(count).to.be.equal(1);
});
it('should sync modifiers if necessary', function(done) {
++count;
break;
case 1:
- expect(evt).to.be.deep.equal({keyId: 0x41, type: 'keydown', keysym: 0x61});
+ expect(evt).to.be.deep.equal({code: 'KeyA', type: 'keydown', keysym: 0x61});
done();
break;
}
- }).keydown({keyCode: 0x41, ctrlKey: true});
+ }).keydown({code: 'KeyA', keyCode: 0x41, ctrlKey: true});
});
it('should forward keydown events with the right type', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.be.deep.equal({keyId: 0x41, type: 'keydown'});
+ expect(evt).to.be.deep.equal({code: 'KeyA', type: 'keydown'});
done();
- }).keydown({keyCode: 0x41});
+ }).keydown({code: 'KeyA', keyCode: 0x41});
});
it('should forward keyup events with the right type', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keyup'});
+ expect(evt).to.be.deep.equal({code: 'KeyA', keysym: 0x61, type: 'keyup'});
done();
- }).keyup({keyCode: 0x41});
+ }).keyup({code: 'KeyA', keyCode: 0x41});
});
it('should forward keypress events with the right type', function(done) {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keypress'});
+ expect(evt).to.be.deep.equal({code: 'KeyA', keysym: 0x61, type: 'keypress'});
done();
- }).keypress({keyCode: 0x41});
+ }).keypress({code: 'KeyA', keyCode: 0x41});
});
it('should generate stalls if a char modifier is down while a key is pressed', function(done) {
var count = 0;
case 2: // 'a'
expect(evt).to.be.deep.equal({
type: 'keydown',
- keyId: 0x41,
+ code: 'KeyA',
keysym: 0x61
});
done();
break;
}
- }).keydown({keyCode: 0x41, altGraphKey: true});
+ }).keydown({code: 'KeyA', keyCode: 0x41, altGraphKey: true});
});
describe('suppress the right events at the right time', function() {
});
obj.keydown({keyCode: 0xe1}); // press altgr
- obj.keydown({keyCode: 'A'.charCodeAt()});
+ obj.keydown({code: 'KeyA', keyCode: 0x41});
});
it('should indicate on events if a single-key char modifier is down', function(done) {
case 1: // 'a'
expect(evt).to.be.deep.equal({
type: 'keypress',
- keyId: 'A'.charCodeAt(),
- keysym: 'a'.charCodeAt(),
+ code: 'KeyA',
+ keysym: 0x61,
escape: [0xfe03]
});
done();
});
obj.keydown({keyCode: 0xe1}); // press altgr
- obj.keypress({keyCode: 'A'.charCodeAt()});
+ obj.keypress({code: 'KeyA', keyCode: 0x41});
});
it('should indicate on events if a multi-key char modifier is down', function(done) {
var times_called = 0;
case 2: // 'a'
expect(evt).to.be.deep.equal({
type: 'keypress',
- keyId: 'A'.charCodeAt(),
- keysym: 'a'.charCodeAt(),
+ code: 'KeyA',
+ keysym: 0x61,
escape: [0xffe9, 0xffe3]
});
done();
obj.keydown({keyCode: 0x11}); // press ctrl
obj.keydown({keyCode: 0x12}); // press alt
- obj.keypress({keyCode: 'A'.charCodeAt()});
+ obj.keypress({code: 'KeyA', keyCode: 0x41});
});
it('should not consider a char modifier to be down on the modifier key itself', function() {
var obj = KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync([0xfe03]), function(evt) {
describe('add/remove keysym', function() {
it('should remove keysym from keydown if a char key and no modifier', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.be.deep.equal({keyId: 0x41, type: 'keydown'});
- }).keydown({keyCode: 0x41});
+ expect(evt).to.be.deep.equal({code: 'KeyA', type: 'keydown'});
+ }).keydown({code: 'KeyA', keyCode: 0x41});
});
it('should not remove keysym from keydown if a shortcut modifier is down', function() {
var times_called = 0;
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
switch (times_called++) {
case 1:
- expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keydown'});
+ expect(evt).to.be.deep.equal({code: 'KeyA', keysym: 0x61, type: 'keydown'});
break;
}
- }).keydown({keyCode: 0x41, ctrlKey: true});
+ }).keydown({code: 'KeyA', keyCode: 0x41, ctrlKey: true});
expect(times_called).to.be.equal(2);
});
it('should not remove keysym from keydown if a char modifier is down', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync([0xfe03]), function(evt) {
switch (times_called++) {
case 2:
- expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keydown'});
+ expect(evt).to.be.deep.equal({code: 'KeyA', keysym: 0x61, type: 'keydown'});
break;
}
- }).keydown({keyCode: 0x41, altGraphKey: true});
+ }).keydown({code: 'KeyA', keyCode: 0x41, altGraphKey: true});
expect(times_called).to.be.equal(3);
});
it('should not remove keysym from keydown if key is noncharacter', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt, 'bacobjpace').to.be.deep.equal({keyId: 0x09, keysym: 0xff09, type: 'keydown'});
+ expect(evt, 'tab').to.be.deep.equal({code: 'Tab', keysym: 0xff09, type: 'keydown'});
}).keydown({keyCode: 0x09});
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt, 'ctrl').to.be.deep.equal({keyId: 0x11, keysym: 0xffe3, type: 'keydown'});
+ expect(evt, 'ctrl').to.be.deep.equal({code: 'ControlLeft', keysym: 0xffe3, type: 'keydown'});
}).keydown({keyCode: 0x11});
});
it('should never remove keysym from keypress', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keypress'});
- }).keypress({keyCode: 0x41});
+ expect(evt).to.be.deep.equal({code: 'KeyA', keysym: 0x61, type: 'keypress'});
+ }).keypress({code: 'KeyA', keyCode: 0x41});
});
it('should never remove keysym from keyup', function() {
KeyboardUtil.KeyEventDecoder(KeyboardUtil.ModifierSync(), function(evt) {
- expect(evt).to.be.deep.equal({keyId: 0x41, keysym: 0x61, type: 'keyup'});
- }).keyup({keyCode: 0x41});
+ expect(evt).to.be.deep.equal({code: 'KeyA', keysym: 0x61, type: 'keyup'});
+ }).keyup({code: 'KeyA', keyCode: 0x41});
});
});
// on keypress, keyup(?), always set keysym
describe('Verify that char modifiers are active', function() {
it('should pass keydown events through if there is no stall', function(done) {
var obj = KeyboardUtil.VerifyCharModifier(function(evt){
- expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x41});
+ expect(evt).to.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x41});
done();
- })({type: 'keydown', keyId: 0x41, keysym: 0x41});
+ })({type: 'keydown', code: 'KeyA', keysym: 0x41});
});
it('should pass keyup events through if there is no stall', function(done) {
var obj = KeyboardUtil.VerifyCharModifier(function(evt){
- expect(evt).to.deep.equal({type: 'keyup', keyId: 0x41, keysym: 0x41});
+ expect(evt).to.deep.equal({type: 'keyup', code: 'KeyA', keysym: 0x41});
done();
- })({type: 'keyup', keyId: 0x41, keysym: 0x41});
+ })({type: 'keyup', code: 'KeyA', keysym: 0x41});
});
it('should pass keypress events through if there is no stall', function(done) {
var obj = KeyboardUtil.VerifyCharModifier(function(evt){
- expect(evt).to.deep.equal({type: 'keypress', keyId: 0x41, keysym: 0x41});
+ expect(evt).to.deep.equal({type: 'keypress', code: 'KeyA', keysym: 0x41});
done();
- })({type: 'keypress', keyId: 0x41, keysym: 0x41});
+ })({type: 'keypress', code: 'KeyA', keysym: 0x41});
});
it('should not pass stall events through', function(done){
var obj = KeyboardUtil.VerifyCharModifier(function(evt){
// should only be called once, for the keydown
- expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x41});
+ expect(evt).to.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x41});
done();
});
obj({type: 'stall'});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x41});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x41});
});
it('should merge keydown and keypress events if they come after a stall', function(done) {
var next_called = false;
// should only be called once, for the keydown
expect(next_called).to.be.false;
next_called = true;
- expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x44});
+ expect(evt).to.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x44});
done();
});
obj({type: 'stall'});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
- obj({type: 'keypress', keyId: 0x43, keysym: 0x44});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x42});
+ obj({type: 'keypress', code: 'KeyC', keysym: 0x44});
expect(next_called).to.be.false;
});
it('should preserve modifier attribute when merging if keysyms differ', function(done) {
// should only be called once, for the keydown
expect(next_called).to.be.false;
next_called = true;
- expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x44, escape: [0xffe3]});
+ expect(evt).to.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x44, escape: [0xffe3]});
done();
});
obj({type: 'stall'});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
- obj({type: 'keypress', keyId: 0x43, keysym: 0x44, escape: [0xffe3]});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x42});
+ obj({type: 'keypress', code: 'KeyC', keysym: 0x44, escape: [0xffe3]});
expect(next_called).to.be.false;
});
it('should not preserve modifier attribute when merging if keysyms are the same', function() {
});
obj({type: 'stall'});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
- obj({type: 'keypress', keyId: 0x43, keysym: 0x42, escape: [0xffe3]});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x42});
+ obj({type: 'keypress', code: 'KeyC', keysym: 0x42, escape: [0xffe3]});
});
it('should not merge keydown and keypress events if there is no stall', function(done) {
var times_called = 0;
var obj = KeyboardUtil.VerifyCharModifier(function(evt){
switch(times_called) {
case 0:
- expect(evt).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42});
+ expect(evt).to.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x42});
break;
case 1:
- expect(evt).to.deep.equal({type: 'keypress', keyId: 0x43, keysym: 0x44});
+ expect(evt).to.deep.equal({type: 'keypress', code: 'KeyC', keysym: 0x44});
done();
break;
}
++times_called;
});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
- obj({type: 'keypress', keyId: 0x43, keysym: 0x44});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x42});
+ obj({type: 'keypress', code: 'KeyC', keysym: 0x44});
});
it('should not merge keydown and keypress events if separated by another event', function(done) {
var times_called = 0;
var obj = KeyboardUtil.VerifyCharModifier(function(evt){
switch(times_called) {
case 0:
- expect(evt,1).to.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42});
+ expect(evt,1).to.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x42});
break;
case 1:
- expect(evt,2).to.deep.equal({type: 'keyup', keyId: 0x43, keysym: 0x44});
+ expect(evt,2).to.deep.equal({type: 'keyup', code: 'KeyC', keysym: 0x44});
break;
case 2:
- expect(evt,3).to.deep.equal({type: 'keypress', keyId: 0x45, keysym: 0x46});
+ expect(evt,3).to.deep.equal({type: 'keypress', code: 'KeyE', keysym: 0x46});
done();
break;
}
});
obj({type: 'stall'});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
- obj({type: 'keyup', keyId: 0x43, keysym: 0x44});
- obj({type: 'keypress', keyId: 0x45, keysym: 0x46});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x42});
+ obj({type: 'keyup', code: 'KeyC', keysym: 0x44});
+ obj({type: 'keypress', code: 'KeyE', keysym: 0x46});
});
});
var obj = KeyboardUtil.TrackKeyState(function(evt) {
expect(true).to.be.false;
});
- obj({type: 'keyup', keyId: 0x41});
+ obj({type: 'keyup', code: 'KeyA'});
});
it('should insert into the queue on keydown if no keys are down', function() {
var times_called = 0;
});
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0x41, keysym: 0x42};
+ elem = {type: 'keydown', code: 'KeyA', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0x41};
+ elem = {type: 'keyup', code: 'KeyA'};
obj(elem);
expect(elem).to.be.null;
expect(times_called).to.be.equal(2);
});
expect(elem).to.be.null;
- elem = {type: 'keypress', keyId: 0x41, keysym: 0x42};
+ elem = {type: 'keypress', code: 'KeyA', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0x41};
+ elem = {type: 'keyup', code: 'KeyA'};
obj(elem);
expect(elem).to.be.null;
expect(times_called).to.be.equal(2);
});
- it('should add keysym to last key entry if keyId matches', function() {
+ it('should add keysym to last key entry if code matches', function() {
// this implies that a single keyup will release both keysyms
var times_called = 0;
var elem = null;
});
expect(elem).to.be.null;
- elem = {type: 'keypress', keyId: 0x41, keysym: 0x42};
+ elem = {type: 'keypress', code: 'KeyA', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keypress', keyId: 0x41, keysym: 0x43};
+ elem = {type: 'keypress', code: 'KeyA', keysym: 0x43};
keysymsdown[0x43] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0x41};
+ elem = {type: 'keyup', code: 'KeyA'};
obj(elem);
expect(times_called).to.be.equal(4);
});
- it('should create new key entry if keyId matches and keysym does not', function() {
+ it('should create new key entry if code matches and keysym does not', function() {
// this implies that a single keyup will release both keysyms
var times_called = 0;
var elem = null;
});
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0, keysym: 0x42};
+ elem = {type: 'keydown', code: 'Unidentified', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0, keysym: 0x43};
+ elem = {type: 'keydown', code: 'Unidentified', keysym: 0x43};
keysymsdown[0x43] = true;
obj(elem);
expect(times_called).to.be.equal(2);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0};
+ elem = {type: 'keyup', code: 'Unidentified'};
obj(elem);
expect(times_called).to.be.equal(3);
- elem = {type: 'keyup', keyId: 0};
+ elem = {type: 'keyup', code: 'Unidentified'};
obj(elem);
expect(times_called).to.be.equal(4);
});
- it('should merge key entry if keyIds are zero and keysyms match', function() {
+ it('should merge key entry if codes are zero and keysyms match', function() {
// this implies that a single keyup will release both keysyms
var times_called = 0;
var elem = null;
});
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0, keysym: 0x42};
+ elem = {type: 'keydown', code: 'Unidentified', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0, keysym: 0x42};
+ elem = {type: 'keydown', code: 'Unidentified', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(times_called).to.be.equal(2);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0};
+ elem = {type: 'keyup', code: 'Unidentified'};
obj(elem);
expect(times_called).to.be.equal(3);
});
- it('should add keysym as separate entry if keyId does not match last event', function() {
+ it('should add keysym as separate entry if code does not match last event', function() {
// this implies that separate keyups are required
var times_called = 0;
var elem = null;
});
expect(elem).to.be.null;
- elem = {type: 'keypress', keyId: 0x41, keysym: 0x42};
+ elem = {type: 'keypress', code: 'KeyA', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keypress', keyId: 0x42, keysym: 0x43};
+ elem = {type: 'keypress', code: 'KeyB', keysym: 0x43};
keysymsdown[0x43] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0x41};
+ elem = {type: 'keyup', code: 'KeyA'};
obj(elem);
expect(times_called).to.be.equal(4);
- elem = {type: 'keyup', keyId: 0x42};
+ elem = {type: 'keyup', code: 'KeyB'};
obj(elem);
expect(times_called).to.be.equal(4);
});
- it('should add keysym as separate entry if keyId does not match last event and first is zero', function() {
+ it('should add keysym as separate entry if code does not match last event and first is zero', function() {
// this implies that separate keyups are required
var times_called = 0;
var elem = null;
});
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0, keysym: 0x42};
+ elem = {type: 'keydown', code: 'Unidentified', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0x42, keysym: 0x43};
+ elem = {type: 'keydown', code: 'KeyB', keysym: 0x43};
keysymsdown[0x43] = true;
obj(elem);
expect(elem).to.be.null;
expect(times_called).to.be.equal(2);
- elem = {type: 'keyup', keyId: 0};
+ elem = {type: 'keyup', code: 'Unidentified'};
obj(elem);
expect(times_called).to.be.equal(3);
- elem = {type: 'keyup', keyId: 0x42};
+ elem = {type: 'keyup', code: 'KeyB'};
obj(elem);
expect(times_called).to.be.equal(4);
});
- it('should add keysym as separate entry if keyId does not match last event and second is zero', function() {
+ it('should add keysym as separate entry if code does not match last event and second is zero', function() {
// this implies that a separate keyups are required
var times_called = 0;
var elem = null;
});
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0x41, keysym: 0x42};
+ elem = {type: 'keydown', code: 'KeyA', keysym: 0x42};
keysymsdown[0x42] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keydown', keyId: 0, keysym: 0x43};
+ elem = {type: 'keydown', code: 'Unidentified', keysym: 0x43};
keysymsdown[0x43] = true;
obj(elem);
expect(elem).to.be.null;
- elem = {type: 'keyup', keyId: 0x41};
+ elem = {type: 'keyup', code: 'KeyA'};
obj(elem);
expect(times_called).to.be.equal(3);
- elem = {type: 'keyup', keyId: 0};
+ elem = {type: 'keyup', code: 'Unidentified'};
obj(elem);
expect(times_called).to.be.equal(4);
});
expect(evt.type).to.be.equal('keydown');
break;
case 3:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x42, keysym: 0x62});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'KeyB', keysym: 0x62});
break;
}
});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x61});
- obj({type: 'keydown', keyId: 0x42, keysym: 0x62});
- obj({type: 'keydown', keyId: 0x43, keysym: 0x63});
- obj({type: 'keyup', keyId: 0x42});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x61});
+ obj({type: 'keydown', code: 'KeyB', keysym: 0x62});
+ obj({type: 'keydown', code: 'KeyC', keysym: 0x63});
+ obj({type: 'keyup', code: 'KeyB'});
expect(times_called).to.equal(4);
});
- it('should pop the first zero keyevent on keyup with zero keyId', function() {
+ it('should pop the first zero keyevent on keyup with zero code', function() {
var times_called = 0;
var obj = KeyboardUtil.TrackKeyState(function(evt) {
switch (times_called++) {
expect(evt.type).to.be.equal('keydown');
break;
case 3:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0x61});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'Unidentified', keysym: 0x61});
break;
}
});
- obj({type: 'keydown', keyId: 0, keysym: 0x61});
- obj({type: 'keydown', keyId: 0, keysym: 0x62});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x63});
- obj({type: 'keyup', keyId: 0x0});
+ obj({type: 'keydown', code: 'Unidentified', keysym: 0x61});
+ obj({type: 'keydown', code: 'Unidentified', keysym: 0x62});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x63});
+ obj({type: 'keyup', code: 'Unidentified'});
expect(times_called).to.equal(4);
});
- it('should pop the last keyevents keysym if no match is found for keyId', function() {
+ it('should pop the last keyevents keysym if no match is found for code', function() {
var times_called = 0;
var obj = KeyboardUtil.TrackKeyState(function(evt) {
switch (times_called++) {
expect(evt.type).to.be.equal('keydown');
break;
case 3:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x44, keysym: 0x63});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'KeyD', keysym: 0x63});
break;
}
});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x61});
- obj({type: 'keydown', keyId: 0x42, keysym: 0x62});
- obj({type: 'keydown', keyId: 0x43, keysym: 0x63});
- obj({type: 'keyup', keyId: 0x44});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x61});
+ obj({type: 'keydown', code: 'KeyB', keysym: 0x62});
+ obj({type: 'keydown', code: 'KeyC', keysym: 0x63});
+ obj({type: 'keyup', code: 'KeyD'});
expect(times_called).to.equal(4);
});
describe('Firefox sends keypress even when keydown is suppressed', function() {
++times_called;
});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x42});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x42});
expect(times_called).to.be.equal(1);
- obj({type: 'keypress', keyId: 0x41, keysym: 0x43});
+ obj({type: 'keypress', code: 'KeyA', keysym: 0x43});
});
});
describe('releaseAll', function() {
var obj = KeyboardUtil.TrackKeyState(function(evt) {
switch (times_called++) {
case 2:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0x41});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'Unidentified', keysym: 0x41});
break;
case 3:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0x42});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'Unidentified', keysym: 0x42});
break;
}
});
- obj({type: 'keydown', keyId: 0x41, keysym: 0x41});
- obj({type: 'keydown', keyId: 0x42, keysym: 0x42});
+ obj({type: 'keydown', code: 'KeyA', keysym: 0x41});
+ obj({type: 'keydown', code: 'KeyB', keysym: 0x42});
expect(times_called).to.be.equal(2);
obj({type: 'releaseall'});
expect(times_called).to.be.equal(4);
KeyboardUtil.EscapeModifiers(function(evt) {
expect(times_called).to.be.equal(0);
++times_called;
- expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42});
- })({type: 'keydown', keyId: 0x41, keysym: 0x42});
+ expect(evt).to.be.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x42});
+ })({type: 'keydown', code: 'KeyA', keysym: 0x42});
expect(times_called).to.be.equal(1);
});
it('should generate fake undo/redo events when a char modifier is down', function() {
KeyboardUtil.EscapeModifiers(function(evt) {
switch(times_called++) {
case 0:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0xffe9});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'Unidentified', keysym: 0xffe9});
break;
case 1:
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0, keysym: 0xffe3});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'Unidentified', keysym: 0xffe3});
break;
case 2:
- expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0x41, keysym: 0x42, escape: [0xffe9, 0xffe3]});
+ expect(evt).to.be.deep.equal({type: 'keydown', code: 'KeyA', keysym: 0x42, escape: [0xffe9, 0xffe3]});
break;
case 3:
- expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0, keysym: 0xffe9});
+ expect(evt).to.be.deep.equal({type: 'keydown', code: 'Unidentified', keysym: 0xffe9});
break;
case 4:
- expect(evt).to.be.deep.equal({type: 'keydown', keyId: 0, keysym: 0xffe3});
+ expect(evt).to.be.deep.equal({type: 'keydown', code: 'Unidentified', keysym: 0xffe3});
break;
}
- })({type: 'keydown', keyId: 0x41, keysym: 0x42, escape: [0xffe9, 0xffe3]});
+ })({type: 'keydown', code: 'KeyA', keysym: 0x42, escape: [0xffe9, 0xffe3]});
expect(times_called).to.be.equal(5);
});
});
KeyboardUtil.EscapeModifiers(function(evt) {
expect(times_called).to.be.equal(0);
++times_called;
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x41, keysym: 0x42, escape: [0xfe03]});
- })({type: 'keyup', keyId: 0x41, keysym: 0x42, escape: [0xfe03]});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'KeyA', keysym: 0x42, escape: [0xfe03]});
+ })({type: 'keyup', code: 'KeyA', keysym: 0x42, escape: [0xfe03]});
expect(times_called).to.be.equal(1);
});
it('should pass through when a char modifier is not down', function() {
KeyboardUtil.EscapeModifiers(function(evt) {
expect(times_called).to.be.equal(0);
++times_called;
- expect(evt).to.be.deep.equal({type: 'keyup', keyId: 0x41, keysym: 0x42});
- })({type: 'keyup', keyId: 0x41, keysym: 0x42});
+ expect(evt).to.be.deep.equal({type: 'keyup', code: 'KeyA', keysym: 0x42});
+ })({type: 'keyup', code: 'KeyA', keysym: 0x42});
expect(times_called).to.be.equal(1);
});
});