Bayern munchen
Bayern munchen

Reputation: 23

Click a specified event on the input in keyboard: up, down, left, right

I need an event that gives one click right, up, down or left. Below is the logic:

if (gesture.left) { Click Event for left direction } Else if (gesture.right) { Click Event for right direction }

I need to detect only one condition after the click button

Upvotes: 1

Views: 47

Answers (2)

user4335601
user4335601

Reputation:

Try this code:

$(function(){
$('html').keydown(function(e){
    if(e.keyCode == 37) { // left
      }
      else if(e.keyCode == 39) { // right
      }
    else if(e.keyCode == 38) { // up
      }
    else if(e.keyCode == 40) { // down
      }
});

});

Upvotes: 1

ajbee
ajbee

Reputation: 3641

arrow keys are only triggered by onkeydown, not onkeypress keycodes are:

left = 37;
up = 38;
right = 39;
down = 40;

or you can look at this thread sample

Upvotes: 0

Related Questions