Skip to content

Commit

Permalink
Track keys pressed with Ctrl combinations, and release them on keyup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Lopez committed May 24, 2016
1 parent 5333590 commit 3c050c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions application/clientgui.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ wdi.ClientGui = $.spcExtend(wdi.EventObject.prototype, {
},

handleKey: function(e) {
console.log("Type: " + e.type + " keyCode: " + e.keyCode);
e.data[0].generateEvent.call(e.data[0], e.type, [e]);

if (wdi.Keymap.isInKeymap(e.keyCode) && e.type !== "keypress") {
Expand Down
29 changes: 25 additions & 4 deletions keymaps/keymap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ wdi.Keymap = {
keymap: {},
ctrlKeymap: {},
charmap: {},
pressedKeyMap: [],
ctrlPressed: false,
twoBytesScanCodes: [0x5B, 0xDB, /*0x38, 0xB8,*/ 0x5C, 0xDC, 0x1D, 0x9D, 0x5D, 0xDD, 0x52, 0xD2, 0x53, 0xD3, 0x4B, 0xCB, 0x47, 0xC9, 0x4F, 0xCF, 0x48, 0xC8, 0x50, 0xD0, 0x49, 0xC9, 0x51, 0xD1, 0x4D, 0xCD, 0x1C, 0x9C],

Expand Down Expand Up @@ -34,10 +35,19 @@ wdi.Keymap = {
* @returns {*}
*/
getScanCodes: function(e) {
if (e['hasScanCode']) {
return e['scanCode'];
} else if (this.handledByCtrlKeyCode(e['type'], e['keyCode'], e['generated'])) {// before doing anything else we check if the event about to be handled has to be intercepted
return this.getScanCodeFromKeyCode(e['keyCode'], e['type'], this.ctrlKeymap, this.reservedCtrlKeymap);
if (e['hasScanCode']) {
return e['scanCode'];
} else if (this.handledByCtrlKeyCode(e['type'], e['keyCode'], e['generated'])) {// before doing anything else we check if the event about to be handled has to be intercepted
scanCodes = this.getScanCodeFromKeyCode(e['keyCode'], e['type'], this.ctrlKeymap, this.reservedCtrlKeymap);
this.pressedKeyMap[e['keyCode']] = scanCodes;
console.log("handleByCtrl: keycode=" + e['keyCode'] + " scancodes=" + scanCodes);
return scanCodes;
} else if (this.handledByPreviousCtrlKeyCode(e['type'], e['keyCode'], e['generated'])) {
scanCodes = this.pressedKeyMap[e['keyCode']];
scanCodes[0][0] = scanCodes[0][0] | 0x80;
console.log("handleByPreviousCtrl: keycode=" + e['keyCode'] + " scancodes=" + scanCodes);
delete this.pressedKeyMap[e['keyCode']];
return scanCodes;
} else if (this.handledByCharmap(e['type'])) {
return this.getScanCodesFromCharCode(e['charCode']);
} else if (this.handledByNormalKeyCode(e['type'], e['keyCode'])) {
Expand Down Expand Up @@ -99,6 +109,17 @@ wdi.Keymap = {
return false;
},

handledByPreviousCtrlKeyCode: function(type, keyCode, generated) {
if (type === 'keyup') {
if (!this.ctrlPressed) {
if (this.pressedKeyMap[keyCode] != undefined) {
return true;
}
}
}
return false;
},

handledByNormalKeyCode: function(type, keyCode) {
if (type === 'keydown' || type === 'keyup') {
if (this.keymap[keyCode]) {
Expand Down
2 changes: 2 additions & 0 deletions process/inputprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ wdi.InputProcess = $.spcExtend(wdi.EventObject.prototype, {
} else if (type == 'keydown' || type == 'keypress') {
scanCodes = wdi.Keymap.getScanCodes(data[1][0]);
for (i= 0; i<scanCodes.length;i++) {
console.log("INPUTS_KEY_DOWN: " + scanCodes[i]);
packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_DOWN,
channel: wdi.SpiceVars.SPICE_CHANNEL_INPUTS,
Expand All @@ -63,6 +64,7 @@ wdi.InputProcess = $.spcExtend(wdi.EventObject.prototype, {
} else if (type == 'keyup') {
scanCodes = wdi.Keymap.getScanCodes(data[1][0]);
for (i= 0; i<scanCodes.length;i++) {
console.log("INPUTS_KEY_UP: " + scanCodes[i]);
packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_INPUTS_KEY_UP,
channel: wdi.SpiceVars.SPICE_CHANNEL_INPUTS,
Expand Down

0 comments on commit 3c050c3

Please sign in to comment.