I have the following code (it basically changes the image I have set depending on the key I press). The problem I am having is when the user presses two keys at the same time. (ex: Right Arrow key and Left Arrow key). How can I prevent output if more than one key is pressed at the same time?
<div id="slide"><img src="http://i.imgur.com/r41vA8p.png" /></div>
</div>
$(document).keydown(function(e){
if (e.keyCode == 37) {
$('#slide').html('<img src="img">');
}
if (e.keyCode == 38) {
$('#slide').html('<img src="img">');
}
if (e.keyCode == 39) {
$('#slide').html('<img src="img">');
}
if (e.keyCode == 40) {
$('#slide').html('<img src="img">');
}
});
Thanks.
Better Explanation:
if left is pressed and held down, then simultaneously right is pressed, no event should occur, nor toggle to right in that instance.
on.('keyup')set to up.leftis pressed and held down, then simultaneouslyrightis pressed, no event should occur ? Not toggle torightin that instance ?