W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2010

Re: what should event.key be if a key inserts multiple characters?

From: Jacob Rossi <rossi@gatech.edu>
Date: Thu, 20 May 2010 19:30:04 -0400
Message-ID: <AANLkTikA_he_xb4qdZyMT1YkLW3cUlJwsf56lIlZStlQ@mail.gmail.com>
To: www-dom@w3.org
Cc: "Hallvord R. M. Steen" <hallvord@opera.com>
>>For example, if keys are
>>configured to insert strings like "Up", "Down", "Left", "Right", "End",
>>"Esc", "Home".. It seems to me that event.key would be set to the
>>corresponding string and there would be no way in our API to distinguish
>>such a key press from pressing the actual up/down/left/right arrow, end,
>>esc or home keys.

I can think of this occurring in 3 different scenarios (each with,
imo, a different outcome):

1. The key was configured to emulate another key. For example, a
configurable key is set up to act like the Up arrow (perhaps an actual
arrow pad doesn't exist or is broken). In this case, (IMO) the
KeyboardEvent should be exactly the same as if the real up arrow were
pressed. Its KeyboardEvent.key value should be "Up".

2. The key was configured to be a macro (of multiple key presses) to
form the text string "Up". In this case, (IMO) this should generate an
IME scenario [1] using the key name (rather than character value) for
the configurable key:

   1. keydown  'KeyName'   (where KeyName is the key name of the
configurable key, as decided by the implementation)
   2. compositionstart ''
   3. keydown 'U'
   4. keyup 'U'
   5. keydown 'p'
   6. compositionend
   7. textInput 'Up'
   8. keyup 'p'
   9. keyup 'KeyName'

3. The key is intended to produce the text string "Up" but not as a
macro of multiple keys. This is the hardest situation to handle. As
you pointed out, it can cause confusion with the actual Up arrow key
(in this example). Currently, the spec prefers character values over
key names. My suggestion would be to modify the spec's preference for
character values (only in the scenario that the character value
collides with the key name of another  key which has no character
value; e.g. Up, Down, etc. ) and instead give the key name for the
configurable key. Then, the textInput event is used to capture the
generated string:

   1. keydown 'KeyName' (KeyName decided by implementation)
   2. textInput 'Up'
   3. keyup 'KeyName'


--Jacob

[1] http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#keyset-IME
Received on Thursday, 20 May 2010 23:30:59 GMT

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