keyup bindings not working in Firefox

Posted by Jarred on Stack Overflow See other posts from Stack Overflow or by Jarred
Published on 2010-03-24T20:37:30Z Indexed on 2010/03/24 20:43 UTC
Read the original article Hit count: 343

Filed under:

Hi. You can see my project here -

http://www.inluxphoto.com/custom/jsgallery/index.php

I am attempting to make the left and right arrow keys move the slideshow. I was able to get it to work in all browsers by following exactly the instructions on the front page of jqueryfordesigners.com (sorry I am only allowed one link).

However, it is necessary that the keyup be unbinded until the animation completes, so the user cannot do a quick double tap of the key, which breaks the show. This led me to the following function -

function keyCommands() {

  //Bind Keys according to keyAssignments
  function keyCommandBind() {
   $(document.documentElement).bind('keyup', keyAssignments)   
  }

  //Bind functions to specific keys
  function keyAssignments() {

   if (event.keyCode == 37) {
    leftArrow();
   }

   if (event.keyCode == 39) {
    rightArrow();
   }

   if (event.keyCode == 32) {
    spaceBar();
   }

  }

  function leftArrow() {
         //unbind, do stuff, rebind
  }

  function rightArrow() {
          //unbind, do stuff, rebind
  }

  function spaceBar() {
          //unbind, do stuff, rebind
  }

  keyCommandBind();

 }

This works in all browsers except Firefox & Camino. Firebug tells me event (ie event.keyCode) is not defined. That's true, it's not defined, and I understand that. However I don't understand why, if it's not defined, does it work in all other browsers.

How can I appropriately define this? Or, am I doing it wrong?

Any help would be most appreciated, thanks for your time!

© Stack Overflow or respective owner

Related posts about jQuery