How can I convert a character to its respective keycode?
For example:
a
to 65
b
to 66
I was searching for this when I stumbled upon this question. I do not think the marked answer is the right answer. For simple letters, A-Za-z, I use the following:
function getKeyCode(char) {
var keyCode = char.charCodeAt(0);
if(keyCode > 90) { // 90 is keyCode for 'z'
return keyCode - 32;
}
return keyCode;
}
Please note that this is meant to work for characters A-Z and a-z only.