This code will fire an alert if I hit either Ctrl key:
$('#text').bind('keypress', function(e) {
if(e.keyCode==17)
{
alert("Boo ya");
}
});
Any way to only fire the alert if only the left Ctrl key is pressed?
keyCode: Returns the Unicode value of a non-character key in a keypress event or any key in any other type of keyboard event. event. charCode: Returns the Unicode value of a character key pressed during a keypress event.
Keycode 13 is the Enter key.
You can't, at least using the keyCode. It'll be 17 for both keys. I don't know of any other method to distinguish between the two, and in my opinion, it's unlikely that there is one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With