Is there a way that we can detect which side the Alt key was pressed on, i.e. distinguish between left or right Alt? I saw somewhere that it’s possible with IE with the altLeft and altRight properties of the Event object. If that is correct, how can we detect it in Firefox with JavaScript?
This is how it works in IE for altLeft:
window.onload = function(){
document.getElementById('id').onkeydown = function(){
alert(window.event.altLeft);
}
}
2015 answer
DOM3 added a
locationproperty of keyboard events (see also MDN) (earlier versions had akeyLocationproperty instead) which does what you want and is implemented in recent versions of all major browsers.Demo:
2011 answer
No. In general, it is impossible to distinguish between left and right modifier keys in a cross-browser way. The
shiftLeft,shiftRight,ctrlLeft,ctrlRight,altLeft,altRightproperties ofwindow.eventare all IE only and no equivalent exists in other browsers.DOM3 added a
locationproperty of keyboard events (earlier versions had akeyLocationproperty instead) but Firefox does not implement this.