0

Hello and i have a question , i have created in html and css 4 buttons , that when hover they do that , when pressed by mouse they do that(:active in css) , but my question is , how can i action them using the arrow keys , because in my project i have to control a rc car using a website and buttons , but for now i want to see how can my buttons work by pressing the arrow keys on my keyboard and do the effect in my :active in css , i searched here but nothing , i am novice when it comes to javascript so bear with me.

Any tips and info are welcome .

  • And also how do so that only when the button is pressed down , without removing the finger do the :active in css , but returns to normal when button is up,that is kinda hard for me to understand now. – Andrei Florea Mar 03 '16 at 18:39
  • See this http://stackoverflow.com/questions/5597060/detecting-arrow-key-presses-in-javascript – Adam Buchanan Smith Mar 03 '16 at 18:40

1 Answers1

0

You'll need to register keypress and possibly keydown event handlers for your text element and then check for the arrow keys in the handler. Similar to this:

      switch (evt.which) {
        // 37 - 40 are the arrow keys
        case 37:
        case 39:
        case 38:
        case 40:

        default:
          break;
      }

The keypress event will trigger when a key is held down.

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71