From a2358a0fc0e1b9afa4050394220143437668ee3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 18 Sep 2011 12:51:03 +0200 Subject: [PATCH] Also fire key events for modifier keys. Closes #52. --- src/ui/Key.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ui/Key.js b/src/ui/Key.js index c8fadd4c..9fdd5099 100644 --- a/src/ui/Key.js +++ b/src/ui/Key.js @@ -93,15 +93,12 @@ var Key = this.Key = new function() { // a keypress, but space would). var key = keys[code], name; if (key) { - // Do not fire handleKey for modifiers, but for other keys such - // ass arrows, delete, backspace, etc. - if (modifiers[name = Base.camelize(key)] !== undefined) { + // Detect modifiers and mark them as pressed + if ((name = Base.camelize(key)) in modifiers) modifiers[name] = true; - } else { - // No char code for special keys, but mark as pressed - charCodeMap[code] = 0; - handleKey(true, code, null, event); - } + // No char code for special keys, but mark as pressed + charCodeMap[code] = 0; + handleKey(true, code, null, event); // Do not set downCode as we handled it already. Space would // be handled twice otherwise, once here, once in keypress. } else { @@ -112,8 +109,8 @@ var Key = this.Key = new function() { keypress: function(event) { if (downCode != null) { var code = event.which || event.keyCode; - // Link the downCode from keydown with the code form keypress, so - // keyup can retrieve that code again. + // Link the downCode from keydown with the code form keypress, + // so keyup can retrieve that code again. charCodeMap[downCode] = code; handleKey(true, downCode, code, event); downCode = null; @@ -123,9 +120,10 @@ var Key = this.Key = new function() { keyup: function(event) { var code = event.which || event.keyCode, key = keys[code], name; - if (key && modifiers[name = Base.camelize(key)] !== undefined) { + // Detect modifiers and mark them as released + if (key && (name = Base.camelize(key)) in modifiers) modifiers[name] = false; - } else if (charCodeMap[code] != null) { + if (charCodeMap[code] != null) { handleKey(false, code, charCodeMap[code], event); delete charCodeMap[code]; }