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

This code issues a warning if I press a key Ctrl:

$('#text').bind('keypress', function(e) {
    if(e.keyCode==17)
    {
        alert("Boo ya");
    }
});

To prevent a warning if only the key is pressed left Ctrl?

+5
source share
2 answers

You cannot at least use keyCode. For both keys there will be 17. I do not know another method to distinguish between the two, and, in my opinion, it is unlikely that there is one.

+2
source

I know this question is pretty old, but today seems possible

$('#text').on("keyup",function(e) {
    console.log(e.originalEvent.code);
    var myKey = e.originalEvent.code;
    if( myKey == 'ControlLeft' )
    {
        alert('hello left control');
    }
});
+1
source

All Articles