[webkit-dev] Changes to keyboard event handling

Alexey Proskuryakov ap-carbon at rambler.ru
Thu Dec 13 00:32:11 PST 2007

   In the latest WebKit nightlies, we have changed keyboard event
handling to match Internet Explorer much more closely. This has fixed
some compatibility bugs, although it remains to be seen whether
significant problems with WebKit-specific content will be uncovered.
It is entirely possible that we will need to undo some or all of these
changes at some point.

   Conceptually, the changes all have a single root cause. We now
treat keydown as an event corresponding to a physical key press which
hasn't been translated with a keyboard layout yet - and keypress
corresponds to a character being typed. Of course, we continue to
support textInput as a more modern text event suitable for
international input.

   Here is a list of changes that were made since Safari 3 release
with Mac OS X 10.5 Leopard:

- Keydown and keyup events have a zero charCode property.
    The reason is that charCode is not known before translating a key
press. These events have a keyCode property whose value is a Windows
virtual key code, and a keyIdentifier property.

- Keypresses do not have a keyIdentifier property.
    The reason is that a character is not necessarily associated with a
single physical key press, so it's not possible to identify a key.
However note that keypress events still have a keyCode property whose
value matches charCode for IE compatibility.

- Arrow keys no longer result in keypress events.
    These do not correspond to characters, and are now processed in
keydown default event handler.

- Tabbing between controls no longer results in keypress and textInput
    Just the same, changing focus is not a character event.

- Backspace and delete also do not generate keypress events any more.

- Modifier keys now generate keydown/keyup events with proper keyCode
and keyIdentifier properties.

- Preventing default handling of a keydown event now prevents keypress
from being sent.

- Preventing default handling of a keydown event no longer prevents
access key handling.

- Pressing Space highlights a button, and releasing it dispatches a
click event.
    Previously, click was dispatched from keypress handler, and the
button was highlighted momentarily. However, Enter key press on a
button still dispatches click from a keypress event default handler to
match IE

- Enter and Return keys can not be differentiated by character code
any more.
    Previously, the code for Enter was erroneously reported as 3. If
needed, these characters can still be differentiated via keyLocation
property of a keydown event.

- Mac only: Emacs editing shortcuts (Ctrl+A, Ctrl+E etc) are now
executed from keydown default handler.
    Behavior of application-defined shortcuts (Cmd+A etc) is still being
looked into, and may also change soon.

   One consequence from the above changes is that Mac key codes (such
as 63232 for up arrow) are never exposed via DOM any more.

- WBR, Alexey Proskuryakov

More information about the webkit-dev mailing list