I have an event listener in Javascript, I can tell whether a key event is Ctrl (e.keyCode == 17)
, but how can I know this Ctrl comes from the right one or left
MSIE provides a ctrlLeft
property on most events. The property values are:
true
if the left key was pressed during the eventfalse
if the left key was not pressed.You can combine event.ctrlKey
and event.ctrlLeft
to determine if the right Ctrl key was pressed:
if (event.ctrlKey) {
if (event.ctrlLeft) {
// left Ctrl key pressed
} else {
// right Ctrl key pressed
}
} else {
// no Ctrl key pressed
}
Note that the ctrlLeft
property in a keyup
is undefined because the Ctrl key is not pressed anymore.
Tested under MSIE7 and MSIE9. Does not work under Firefox.
See http://help.dottoro.com/ljqlvhuf.php for details.