Good question. The event object does not contain anything about which alt is pressed but you can try something like this:
var altLeft = false,
altRight = false,
time = null;
document.onkeydown = function (e) {
e = e || window.event;
//The time check is because firefox triggers alt Right + alt Left when you press alt Right so you must skip alt Left if it comes immediatelly after alt Right
if (e.keyCode === 18 && (time === null || ((+new Date) - time) > 50)) {
altLeft = true;
time = null;
} else if (e.keyCode === 17) {
altRight = true;
time = + new Date;
}
}
document.onkeyup = function (e) {
e = e || window.event;
if (e.keyCode === 18) altLeft = false;
else if (e.keyCode === 17) altRight = false;
}
document.onclick = function () {
console.log("left", altLeft, "right", altRight);
}
It works for me in Firefox, anyway the 17 and 18 (that are key codes for alt Right and Left) can change on different browsers or operating systems so you must check them.