how do i check if a combination of keys are pressed with jquery?
lets say i want to fire up an alert only when the up and down arrow keys are pressed at the same time.
right now im just using:
switch (event.which) {
case 40:
alert('down');
break;
case 38:
alert('up');
break;
case 37:
alert('left');
break;
case 39:
alert('right');
break;
}
Set flags. When one key goes down, if it’s a certain keyCode, set your flag
myKeyIsDown = true. When it comes up, set the flag back to false. When your second key goes down, if it is of a certain keyCode and yourmyKeyIsDownflag is true, you’ve got two keys down.