سؤال

I'm trying to handle key events to a canvas. I've added a tabindex which allows the canvas to receive events. My problem is that keydown events aren't registering. They are still going to the document. I can get letter key events but not the standard arrow keys (or at least in everything but FF).

So I guess my question is how do I handle arrow key events in IE, Safari and Chrome? I get "sort of handled" in all browsers with letters and numbers. Just not arrow keys.

Thanks a bunch.

$('#tetris-canvas').keypress(function(e){
  e.preventDefault();
  alert('sort of handled');
  tetris.keyHandler(e);
});

My page is at http://tetris.townsendwebdd.com/ if you want to see the whole code

so changed it to $(document).keypress(yada); safari still doesn't handle arrows

هل كانت مفيدة؟

المحلول

Try this:

$(#tetris-canvas).keydown(function(e) {
    e.preventDefault();
    e.stopPropagation();
    // your code...
});​
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top