W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2011

RE: Replacing the event keyCode value.

From: Brad Pettit <Brad.Pettit@microsoft.com>
Date: Fri, 2 Dec 2011 01:53:05 +0000
To: João Eiras <joaoe@opera.com>, "www-dom@w3.org" <www-dom@w3.org>
Message-ID: <315305B72700D143ABB3FEE4E68637A80791E469@TK5EX14MBXC212.redmond.corp.microsoft.com>
Having the keycode modifiable would be problematic because multiple listeners may be attached to an EventTarget, and the order of execution for EventListeners on any given node is not defined. In one implementation, the listener that modifies the code might execute first, while on another, it might execute last.

<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-basic>
"Although all EventListeners on the EventTarget are guaranteed to be triggered by any event which is received by that EventTarget, no specification is made as to the order in which they will receive the event with regards to the other EventListeners on the EventTarget"

Also, the code for a keydown/keyup is a physical key transition. Changing the key code does not mean a corresponding keypress value would be generated.

-----Original Message-----
From: João Eiras [mailto:joaoe@opera.com] 
Sent: Thursday, December 01, 2011 4:54 PM
To: www-dom@w3.org
Subject: Re: Replacing the event keyCode value.

On , Aryeh Gregor <ayg@aryeh.name> wrote:

> On Wed, Nov 23, 2011 at 9:00 AM, Olli Pettay <Olli.Pettay@helsinki.fi>
> wrote:
>> Replace the value of keyCode in which way?
>> Could you give an example what used to work and what doesn't work 
>> anymore. Also, note that Internet Explorer didn't support DOM events 
>> before IE9, although other browsers did.
>
> Links to the discussions you found would be useful too.
>

IE allows the keyCode property in the event object to be assigned, like

# if (event.keyCode == 27) event.keyCode = 13;

and with a special quirk, assigning 0 prevents the event.

This is Microsoft's proprietary behavior, and if that is a serious interoperability issue, then you should use the X-UA-Compatible header or meta tag, or Microsft could allow keyCode to be writable from event listeners registered using attachEvent.

Anyway, not a specification issue. The specification has been like this since ever.


Received on Friday, 2 December 2011 02:05:01 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:08 GMT