Take the 2-minute tour ×

I have very simple javascript project, and i want to translate my <div> with onclick events. How can read keyboard values from user to run my function? I need only arrow buttons. Thanx.

upButton.onclick = function() {
share|improve this question
onkeyup, onkeydown –  Marc B Sep 3 '12 at 5:54
add comment

2 Answers

My answer here is how it's done for determining exactly what was pressed: What's the best way to create key events in HTML5 canvas?

Edit: As my answer at that link states: you cannot just grab the arrow keys, but rather you have to listen for all keys and then determine if it's the key you want and then do whatever function/action you want. All of which is stated in that answer.

share|improve this answer
add comment

In order for your users to use up, down, left, and right keyboard functions, you must be able to know how to use onkeypress events on javascript.

If you are using javascript, here is a link for onkeypress: http://www.w3schools.com/jsref/event_onkeypress.asp

If you are using jquery, here is a link for .keypress():

The code for the arrow is as follows:

  • 37 - left
  • 38 - up
  • 39 - right
  • 40 - down
share|improve this answer
add comment

Your Answer


