Skip to content

Commit

Permalink
devtools: fix keysim to follow a07e75f
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Jun 26, 2016
1 parent 4704bfc commit 7bd6e44
Showing 1 changed file with 89 additions and 10 deletions.
99 changes: 89 additions & 10 deletions resources/unpacked/devtools/front_end/dirac/keysim.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,87 @@

/* jshint esnext:true, undef:true, unused:true */

var keyCodeToKeyIdentifierMap = {
9: "U+0009", // tab
27: "U+001B", // esc
32: "U+0020", // space
38: 'Up',
40: 'Down',
37: 'Left',
39: 'Right',
// taken from devtools.js
var staticKeyIdentifiers = new Map([
[0x12, "Alt"],
[0x11, "Control"],
[0x10, "Shift"],
[0x14, "CapsLock"],
[0x5b, "Win"],
[0x5c, "Win"],
[0x0c, "Clear"],
[0x28, "Down"],
[0x23, "End"],
[0x0a, "Enter"],
[0x0d, "Enter"],
[0x2b, "Execute"],
[0x70, "F1"],
[0x71, "F2"],
[0x72, "F3"],
[0x73, "F4"],
[0x74, "F5"],
[0x75, "F6"],
[0x76, "F7"],
[0x77, "F8"],
[0x78, "F9"],
[0x79, "F10"],
[0x7a, "F11"],
[0x7b, "F12"],
[0x7c, "F13"],
[0x7d, "F14"],
[0x7e, "F15"],
[0x7f, "F16"],
[0x80, "F17"],
[0x81, "F18"],
[0x82, "F19"],
[0x83, "F20"],
[0x84, "F21"],
[0x85, "F22"],
[0x86, "F23"],
[0x87, "F24"],
[0x2f, "Help"],
[0x24, "Home"],
[0x2d, "Insert"],
[0x25, "Left"],
[0x22, "PageDown"],
[0x21, "PageUp"],
[0x13, "Pause"],
[0x2c, "PrintScreen"],
[0x27, "Right"],
[0x91, "Scroll"],
[0x29, "Select"],
[0x26, "Up"],
[0x2e, "U+007F"], // Standard says that DEL becomes U+007F.
[0xb0, "MediaNextTrack"],
[0xb1, "MediaPreviousTrack"],
[0xb2, "MediaStop"],
[0xb3, "MediaPlayPause"],
[0xad, "VolumeMute"],
[0xae, "VolumeDown"],
[0xaf, "VolumeUp"],
]);

function keyCodeToKeyIdentifier(keyCode)
{
var result = staticKeyIdentifiers.get(keyCode);
if (result !== undefined)
return result;
result = "U+";
var hexString = keyCode.toString(16).toUpperCase();
for (var i = hexString.length; i < 4; ++i)
result += "0";
result += hexString;
return result;
}

var keyCodeToKeyMap = {
9: "Tab", // tab
27: "Escape", // esc
32: " ", // space
38: 'ArrowUp',
40: 'ArrowDown',
37: 'ArrowLeft',
39: 'ArrowRight',
13: 'Enter',
112: 'F1',
113: 'F2',
Expand All @@ -118,6 +191,11 @@
45: 'Insert'
};

function keyCodeToKey(keyCode) {
return keyCodeToKeyMap[keyCode] || String.fromCharCode(keyCode);
}


var CTRL = 1 << 0;
var META = 1 << 1;
var ALT = 1 << 2;
Expand Down Expand Up @@ -278,7 +356,8 @@
event.keyCode = type === 'keypress' ? this.charCodeForKeystroke(keystroke) : keystroke.keyCode;
event.charCode = type === 'keypress' ? event.keyCode : 0;
event.which = event.keyCode;
event.keyIdentifier = keyCodeToKeyIdentifierMap[event.keyCode];
event.keyIdentifier = keyCodeToKeyIdentifier(event.keyCode);
event.key = keyCodeToKey(event.keyCode);
break;
}

Expand Down Expand Up @@ -727,4 +806,4 @@
exports.Keystroke = Keystroke;
exports.Keyboard = Keyboard;

}));
}));

0 comments on commit 7bd6e44

Please sign in to comment.