Way too complicated. I wonder if this works on the dead keys (`~^'"). This is the easy way:
var charCode = event.key.charCodeAt(0); var character = String.fromCharCode(charCode);
You also have to realise that String.fromCharCode(event.keyCode) is very wrong. A charCode is not the same as a keyCode.