How do I go about binding a function to left and right arrow keys in Javascript and/or jQuery? I looked at the js-hotkey plugin for jQuery (wraps the built-in bind function to add an argument to recognize specific keys), but it doesn’t seem to support arrow keys.
Share
If you need to support IE8, start the function body as
e = e || window.event; switch(e.which || e.keyCode) {.(edit 2020)
Note that
KeyboardEvent.whichis now deprecated. See this example usingKeyboardEvent.keyfor a more modern solution to detect arrow keys.