views:

459

answers:

2

I'm making a facebook game and the users asked me to make the game start by pressing spacebar, because clicking on a button wastes their time. I tried to make it by this code:

jQuery("body").focus().bind('keyup', function (e) { if ( e.keyCode == 32 ){
   startgame();
}});

But this code doesn't work in the app (http://apps.facebook.com/typepractice/), but it works in the site (http://typepractice.php5.sk/). Is Facebook blocking the key events? Please, help me.

A: 

I find that the Spacebar-to-start doesn't work on either the facebook app, or the site. I think your jQuery may simply not work.

graphicdivine
A: 

I made it work by adding event to a button, not a body element. It works now

jQuery(".game input[type='button']")
.focus()
.css({"cursor":"pointer"})
.click(startgame)
.keyup(function (e) {
       if ( e.keyCode == 32 ){
           startgame();
           return false;
        }
});
Michal