Re: Proposal: addKeyListener and removeKeyListener Methods

Why add/removeKeyListener methods are for bubble phase only?
And also, why only keydown? Why not keyup and keypress?

Also, how should the listener work if keydown isn't a keyboardevent?
var e = document.createEvent("Event");
e.initEvent("keydown", false, false);

It is pretty easy to add listeners to listen only specific
keys. You just need to filter the events in the listener, not
when registering the listener.

(Though, I agree, if some good API for this all was figured out, this 
would simplify some use cases. The current API isn't just enough.)


Doug Schepers wrote:
> Hi, DOM3 Events fans-
> Since DOM3 Events now has a more robust (and standardized) keyboard 
> event model, it seemed appropriate to consider more closely how it might 
> be used. As an input device, the keyboard is particularly complicated, 
> with many keys having dedicated functionality. To some degree, I 
> addressed this in the description of default actions of the 'keydown' 
> event [1], but there have been many times where I wished to listen only 
> to specific keys. It's easy enough to filter out the keys using the 
> "if...else" or "switch" statements in the event handler, but it would be 
> nice to attach different listeners to different keys to dispatch to 
> different event handlers.
> Thus, I've tentatively added a proposal for new 'addKeyListener' and 
> 'removeKeyListener' methods to the Event interface, which you can review 
> and comment on in the latest draft. [2]
> I'm open to suggestions to improve this idea, and obviously it depends 
> on implementers' willingness to include it, but I would personally like 
> some mechanism to do this.
> [1] 
> [2] 
> Regards-
> -Doug Schepers
> W3C Team Contact, SVG and WebApps WGs

Received on Sunday, 13 September 2009 12:32:13 UTC