Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you distinguish between the left CTRL key and right CTRL key using keycodes in .keypress()?

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?

like image 570
wkm Avatar asked Dec 10 '10 01:12

wkm


People also ask

What is the difference between keyCode and charCode?

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.

What is e keyCode === 13?

Keycode 13 is the Enter key.


1 Answers

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.

like image 104
MartinodF Avatar answered Sep 30 '22 03:09

MartinodF