Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #75 from Burgestrand/isPressedPatch

key descriptions (e.g. 'up', 'space', etc) in key.isPressed()
  • Loading branch information...
commit e235689eea5a9f3a5beb590b8ae491531e8a6ba5 2 parents 84df69f + 626a50f
@madrobby authored
Showing with 9 additions and 6 deletions.
  1. +5 −6 keymaster.js
  2. +4 −0 test/keymaster.html
View
11 keymaster.js
@@ -29,6 +29,9 @@
';': 186, '\'': 222,
'[': 219, ']': 221, '\\': 220
},
+ code = function(x){
+ return _MAP[x] || x.toUpperCase().charCodeAt(0);
+ },
_downKeys = [];
for(k=1;k<20;k++) _MODIFIERS['f'+k] = 111+k;
@@ -136,7 +139,7 @@
}
// convert to keycode and...
key = key[0]
- key = _MAP[key] || key.toUpperCase().charCodeAt(0);
+ key = code(key);
// ...store handler
if (!(key in _handlers)) _handlers[key] = [];
_handlers[key].push({ shortcut: keys[i], scope: scope, method: method, key: keys[i], mods: mods });
@@ -147,11 +150,7 @@
// Converts strings into key codes.
function isPressed(keyCode) {
if (typeof(keyCode)=='string') {
- if (keyCode.length == 1) {
- keyCode = (keyCode.toUpperCase()).charCodeAt(0);
- } else {
- return false;
- }
+ keyCode = code(keyCode);
}
return index(_downKeys, keyCode) != -1;
}
View
4 test/keymaster.html
@@ -239,6 +239,10 @@
keydown(66); keyup(66);
t.assertFalse(key.isPressed(66));
+
+ keydown(38);
+ t.assertTrue(key.isPressed("up"));
+ keyup(38);
},
testGetPressedKeyCodes: function (t) {
Please sign in to comment.
Something went wrong with that request. Please try again.