Query about using keyboard for next / prev links

I have a photo site. Each pages checks to see where it is in the sequence of photos - if you’re mid way through a sequence, you can use the thumbnails to click prev / next photo - e.g.:


I wondered if it would be possible to use Javascript to allow the user to click left on their keyboard to go back one page in the seq. and right to go forward one page.

Any advice much appreciated.


Yes. You need to capture the onkeypress (or onkeyup or onkeydown) event and check what key was pressed.

    document.onkeydown = function(e) {
      if (!e) var e = window.event;
      switch (e.keyCode || e.which) {
        case 188: previous(); break; // left arrow
        case 190: next(); break; // right arrow