Improve handling of special characters and control sequences.

This commit is contained in:
Jürg Lehni 2015-12-20 11:32:16 +01:00
parent 0346552bc6
commit 4ee3a76a74

View file

@ -18,6 +18,7 @@ var Key = new function() {
var keyLookup = { var keyLookup = {
// Unify different naming scheme, e.g. Gecko, IE, ... // Unify different naming scheme, e.g. Gecko, IE, ...
' ': 'space', ' ': 'space',
'\t': 'tab',
'Spacebar': 'space', 'Spacebar': 'space',
'Win': 'meta', 'Win': 'meta',
'Del': 'delete', 'Del': 'delete',
@ -155,8 +156,12 @@ var Key = new function() {
keypress: function(event) { keypress: function(event) {
if (downKey) { if (downKey) {
handleKey(true, downKey, String.fromCharCode(event.charCode), var code = event.charCode;
event); // Try event.charCode if its above 32 and fall back onto the
// key value if it's a single character, empty otherwise.
handleKey(true, downKey, code >= 32
? String.fromCharCode(code)
: downKey.length > 1 ? '' : downKey, event);
downKey = null; downKey = null;
} }
}, },