Search code examples
javascriptjquerykeypress

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?


Solution

  • 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.