You can get the keyCode
of a key pressed in jQuery:
$('#myField').keydown(function(event) {
console.log(event.which);
});
How do I compare that to a letter? I could, of course, find out the keyCode of that letter, but I don't know ahead of time what that letter is. So I could convert every letter to a keyCode and look that up in an object. I have to imagine there's an easier way for this common situation?
Does myLetter.charCodeAt(0)
always give me the same number as event.which
for the same letter?