How could I identify which Ctrl / Shift / Alt keys are pressed in the following code ?
$("#my_id").click(function() { if (<left control key is pressed>) { alert("Left Ctrl"); } if (<right shift and left alt keys are pressed>) { alert("Right Shift + Left Alt"); } });
Well you this wont work in all browsers just IE 8. Microsoft implemented the ability to determine which (right/left) key was pressed. Here is a link http://msdn.microsoft.com/en-us/library/ms534630(VS.85).aspx
I also found this wonder article about keypress, keyup, keydown event in browsers. http://unixpapa.com/js/key.html
$('#someelement').bind('click', function(event){ if(event.ctrlKey) { if (event.ctrlLeft) { console.log('ctrl-left'); } else { console.log('ctrl-right'); } } if(event.altKey) { if (event.altLeft) { console.log('alt-left'); } else { console.log('alt-right'); } } if(event.shiftKey) { if (event.shiftLeft) { console.log('shift-left'); } else { console.log('shift-right'); } } });
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