You have assumed that keyCode
gives you an ASCII index, but that is not true. Your range criteria are incorrect due to this assumption.
MDN says:
In a keypress
event, the Unicode value of the key pressed is stored in either the keyCode
or charCode
property, never both. If the key pressed generates a character (e.g. 'a'), charCode
is set to the code of that character, respecting the letter case. (i.e. charCode
takes into account whether the shift key is held down). Otherwise, the code of the pressed key is stored in keyCode
.
keyCode
is always set in the keydown and keyup events. In these cases, charCode is never set.
To get the code of the key regardless of whether it was stored in keyCode
or charCode
, query the which property.
For a list of the keyCode values associated with particular keys, run the example in Example 7: Displaying Event Object Constants and view the resulting HTML table.
Doing as instructed reveals that some of your "special" characters lie outside of the range limits you've specified.
Kevin also pointed out this useful table, but you'd be best off using a more canonical approach to keypress handling.