Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-15 Thread Bjartur Thorlacius
On 6/14/10, Kornel Lesinski  wrote:
> On Mon, 14 Jun 2010 20:38:07 +0100, Carlos Andrés Solís
>  wrote:
>
>> Hello! I've been noticing a problem in many HTML5 test apps, very
>> especially games. When the directional arrow buttons are pressed, the
>> screen scrolls.
>> This is a problem that, as far as I know, Flash had solved by changing
>> the focus of the application to the app. Is this doable in HTML5?
>
> Yes. It's possible already — page just has to return false from keypress
> handler:
>
> window.onkeypress = function(){return false}
>
> That's just one line that, unfortunately, many web-based games forget to
> include.
>
The bad thing about the Flash behaviour is that it seems to completely steal
keyboard focus if programs even listen to onkeypress. window.onkeydown
should return false only when the application is actually going to use that
keypress.

-- 
kv,
  - Bjartur


Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Tab Atkins Jr.
On Mon, Jun 14, 2010 at 3:56 PM, Simon Pieters  wrote:
> On Tue, 15 Jun 2010 00:16:13 +0200, Kornel Lesinski 
> wrote:
>
>> On Mon, 14 Jun 2010 20:38:07 +0100, Carlos Andrés Solís
>>  wrote:
>>
>>> Hello! I've been noticing a problem in many HTML5 test apps, very
>>> especially games. When the directional arrow buttons are pressed, the screen
>>> scrolls.
>>> This is a problem that, as far as I know, Flash had solved by changing
>>> the focus of the application to the app. Is this doable in HTML5?
>>
>> Yes. It's possible already — page just has to return false from keypress
>> handler:
>>
>> window.onkeypress = function(){return false}
>>
>> That's just one line that, unfortunately, many web-based games forget to
>> include.
>
> If a game is embedded in a page with other content, it could make the
>  (or whatever) focusable with tabindex='0' and only disable keys
> when the game has focus. It could also be nice and only disable the keys it
> chooses to use.
>
> 
> var mapping = {37: 'left', 38: 'up', 39: 'right', 40:'down'}
> function press(e) {
>  if (!e.shiftKey && !e.ctrlKey && !e.metaKey && e.keyCode > 36 && e.keyCode
> < 41) {
>    var ctx = e.target.getContext('2d');
>    ctx.clearRect(0, 0, e.target.width, e.target.height);
>    ctx.fillText(mapping[e.keyCode], 20, 20);
>    e.preventDefault();
>  }
> }
> 
> 
>
> In Opera, I can scroll using the arrow keys, navigate to the game, interact
> with it using the arrow keys without it scrolling the page, and navigate
> away from it using spatnav (shift+arrow keys).

Random note: the keypress event isn't interoperably supported in this
area - in IE and webkit-based browsers, keys that don't generate a
character won't generate a keypress event.  You can use keydown to
capture the press instead.

~TJ


Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Simon Pieters
On Tue, 15 Jun 2010 00:16:13 +0200, Kornel Lesinski   
wrote:


On Mon, 14 Jun 2010 20:38:07 +0100, Carlos Andrés Solís  
 wrote:


Hello! I've been noticing a problem in many HTML5 test apps, very  
especially games. When the directional arrow buttons are pressed, the  
screen scrolls.
This is a problem that, as far as I know, Flash had solved by changing  
the focus of the application to the app. Is this doable in HTML5?


Yes. It's possible already — page just has to return false from keypress  
handler:


window.onkeypress = function(){return false}

That's just one line that, unfortunately, many web-based games forget to  
include.


If a game is embedded in a page with other content, it could make the  
 (or whatever) focusable with tabindex='0' and only disable keys  
when the game has focus. It could also be nice and only disable the keys  
it chooses to use.



var mapping = {37: 'left', 38: 'up', 39: 'right', 40:'down'}
function press(e) {
if (!e.shiftKey && !e.ctrlKey && !e.metaKey && e.keyCode > 36 && e.keyCode < 41) {
var ctx = e.target.getContext('2d');
ctx.clearRect(0, 0, e.target.width, e.target.height);
ctx.fillText(mapping[e.keyCode], 20, 20);
e.preventDefault();
  }
}



In Opera, I can scroll using the arrow keys, navigate to the game,  
interact with it using the arrow keys without it scrolling the page, and  
navigate away from it using spatnav (shift+arrow keys).


--
Simon Pieters
Opera Software


Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Kornel Lesinski
On Mon, 14 Jun 2010 20:38:07 +0100, Carlos Andrés Solís  
 wrote:


Hello! I've been noticing a problem in many HTML5 test apps, very  
especially games. When the directional arrow buttons are pressed, the  
screen scrolls.
This is a problem that, as far as I know, Flash had solved by changing  
the focus of the application to the app. Is this doable in HTML5?


Yes. It's possible already — page just has to return false from keypress  
handler:


window.onkeypress = function(){return false}

That's just one line that, unfortunately, many web-based games forget to  
include.


--
regards, Kornel Lesiński


Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Ashley Sheridan
On Mon, 2010-06-14 at 15:58 -0400, Gordon P. Hemsley wrote:

> For what it's worth, I am actually of the opposite opinion, Ash.
> 
> I like it when Flash steals the focus of the keyboard, and here's why:
> Besides the arrow keys, which are available to everyone, I also use
> the "Find As You Type" feature in Firefox. However, that usually means
> that I can't play any HTML5 games that use letters as play keys.
> Because the HTML5 game usually doesn't steal the focus of the
> keyboard, typing a letter key activates the FAYT feature and distracts
> me from the game.
> 
> With that being said, Bespin (from Mozilla Labs) uses , and it
> has no problem stealing the keyboard focus (with JavaScript) for most
> keypresses.
> 
> Gordon
> 
> 
> 2010/6/14 Ashley Sheridan 
> 
> On Mon, 2010-06-14 at 13:38 -0600, Carlos Andrés Solís wrote:
> 
> > Hello! I've been noticing a problem in many HTML5 test apps,
> > very especially games. When the directional arrow buttons
> > are pressed, the screen scrolls. This is a problem that, as
> > far as I know, Flash had solved by changing the focus of the
> > application to the app. Is this doable in HTML5?
> > - Carlos Solís
> 
> 
> 
> 
> I don't think it's something that was 'solved'  by Flash. To
> be honest, I'm often annoyed at the way Flash steals the focus
> of all my key presses making it almost impossible to navigate
> using only the keyboard.
> 
> You could use Javascript to put the focus onto an object,
> capture all the key presses on that and return false for them
> all maybe.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
> 
> 
> 
> 
> 
> -- 
> Gordon P. Hemsley
> m...@gphemsley.org
> http://gphemsley.org/ • http://gphemsley.org/blog/
> http://sasha.sourceforge.net/ • http://www.yoursasha.com/


It's not that I have it in for Flash, but I feel it's not the most
accessibility friendly of things you find on the web.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Gordon P. Hemsley
For what it's worth, I am actually of the opposite opinion, Ash.

I like it when Flash steals the focus of the keyboard, and here's why:
Besides the arrow keys, which are available to everyone, I also use the
"Find As You Type" feature in Firefox. However, that usually means that I
can't play any HTML5 games that use letters as play keys. Because the HTML5
game usually doesn't steal the focus of the keyboard, typing a letter key
activates the FAYT feature and distracts me from the game.

With that being said, Bespin (from Mozilla Labs) uses , and it has
no problem stealing the keyboard focus (with JavaScript) for most
keypresses.

Gordon

2010/6/14 Ashley Sheridan 

>  On Mon, 2010-06-14 at 13:38 -0600, Carlos Andrés Solís wrote:
>
> Hello! I've been noticing a problem in many HTML5 test apps, very
> especially games. When the directional arrow buttons are pressed, the screen
> scrolls. This is a problem that, as far as I know, Flash had solved by
> changing the focus of the application to the app. Is this doable in HTML5?
> - Carlos Solís
>
>
> I don't think it's something that was 'solved'  by Flash. To be honest, I'm
> often annoyed at the way Flash steals the focus of all my key presses making
> it almost impossible to navigate using only the keyboard.
>
> You could use Javascript to put the focus onto an object, capture all the
> key presses on that and return false for them all maybe.
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


-- 
Gordon P. Hemsley
m...@gphemsley.org
http://gphemsley.org/ • http://gphemsley.org/blog/
http://sasha.sourceforge.net/ • http://www.yoursasha.com/


Re: [whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Ashley Sheridan
On Mon, 2010-06-14 at 13:38 -0600, Carlos Andrés Solís wrote:

> Hello! I've been noticing a problem in many HTML5 test apps, very
> especially games. When the directional arrow buttons are pressed, the
> screen scrolls. This is a problem that, as far as I know, Flash had
> solved by changing the focus of the application to the app. Is this
> doable in HTML5?
> - Carlos Solís


I don't think it's something that was 'solved'  by Flash. To be honest,
I'm often annoyed at the way Flash steals the focus of all my key
presses making it almost impossible to navigate using only the keyboard.

You could use Javascript to put the focus onto an object, capture all
the key presses on that and return false for them all maybe.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[whatwg] Is there a way to stop scrolling when pressing directional arrows?

2010-06-14 Thread Carlos Andrés Solís
Hello! I've been noticing a problem in many HTML5 test apps, very especially
games. When the directional arrow buttons are pressed, the screen scrolls.
This is a problem that, as far as I know, Flash had solved by changing the
focus of the application to the app. Is this doable in HTML5?
- Carlos Solís