Skip to content

Commit

Permalink
ignore invalid keycodes
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jun 21, 2016
1 parent 6906f82 commit 2c08bfd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/keyboard_input.es6
Expand Up @@ -70,6 +70,12 @@ export const SYMBOL_MAP = {
222: "\'",
}

export const SYMBOL_MAP_INVERSE = {}

for (let key in SYMBOL_MAP) {
SYMBOL_MAP_INVERSE[SYMBOL_MAP[key]] = key
}

export function keyCodeToChar(keyCode) {
const symbol = SYMBOL_MAP[keyCode]

Expand All @@ -78,7 +84,13 @@ export function keyCodeToChar(keyCode) {
}

if (keyCode >= 32 || keyCode < 127) {
return String.fromCharCode(keyCode).toLowerCase()
let chr = String.fromCharCode(keyCode).toLowerCase()

if (SYMBOL_MAP_INVERSE[chr]) {
return // invalid symbol
}

return chr
}
}

Expand Down

0 comments on commit 2c08bfd

Please sign in to comment.