keyhandler.js
This file contains a class for working with keyboard events that repeat consistently across browsers and platforms. It also unifies the key code so that it is the same in all browsers and platforms. Different web browsers have very different keyboard event handling. Most importantly is that only certain browsers repeat keydown events: IE, Opera, FF/Win32, and Safari 3 repeat keydown events. FF/Mac and Safari 2 do not. For the purposes of this code, "Safari 3" means WebKit 525+, when WebKit decided that they should try to match IE's key handling behavior. Safari 3.0.4, which shipped with Leopard (WebKit 523), has the Safari 2 behavior. Firefox, Safari, Opera prevent on keypress IE prevents on keydown Firefox does not fire keypress for shift, ctrl, alt Firefox does fire keydown for shift, ctrl, alt, meta Firefox does not repeat keydown for shift, ctrl, alt, meta Firefox does not fire keypress for up and down in an input Opera fires keypress for shift, ctrl, alt, meta Opera does not repeat keypress for shift, ctrl, alt, meta Safari 2 and 3 do not fire keypress for shift, ctrl, alt Safari 2 does not fire keydown for shift, ctrl, alt Safari 3 *does* fire keydown for shift, ctrl, alt IE provides the keycode for keyup/down events and the charcode (in the keycode field) for keypress. Mozilla provides the keycode for keyup/down and the charcode for keypress unless it's a non text modifying key in which case the keycode is provided. Safari 3 provides the keycode and charcode for all events. Opera provides the keycode for keyup/down event and either the charcode or the keycode (in the keycode field) for keypress events. Firefox x11 doesn't fire keydown events if a another key is already held down until the first key is released. This can cause a key event to be fired with a keyCode for the first key and a charCode for the second key. Safari in keypress charCode keyCode which ENTER: 13 13 13 F1: 63236 63236 63236 F8: 63243 63243 63243 ... p: 112 112 112 P: 80 80 80 Firefox, keypress: charCode keyCode which ENTER: 0 13 13 F1: 0 112 0 F8: 0 119 0 ... p: 112 0 112 P: 80 0 80 Opera, Mac+Win32, keypress: charCode keyCode which ENTER: undefined 13 13 F1: undefined 112 0 F8: undefined 119 0 ... p: undefined 112 112 P: undefined 80 80 IE7, keydown charCode keyCode which ENTER: undefined 13 undefined F1: undefined 112 undefined F8: undefined 119 undefined ... p: undefined 80 undefined P: undefined 80 undefined

File Location

events/keyhandler.js

Classes

goog.events.KeyHandler
A wrapper around an element that you want to listen to keyboard events on. XXX: {Document|Element} != {Element|Document}. see: http://b/1470354
goog.events.KeyEvent
This class is used for the goog.events.KeyHandler.EventType.KEY event and it overrides the key code with the fixed key code.

Public Protected Private

Global Properties

goog.events.KeyHandler.USES_KEYDOWN_ :
If true, the KeyEvent fires on keydown. Otherwise, it fires on keypress.
Code »
goog.events.KeyHandler.keyIdentifier_ :
An enumeration of key identifiers currently part of the W3C draft for DOM3 and their mappings to keyCodes. http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set This is currently supported in Safari and should be platform independent.
Code »
goog.events.KeyHandler.mozKeyCodeToKeyCodeMap_ :
Map from Gecko specific key codes to cross browser key codes
Code »
goog.events.KeyHandler.safariKey_ :
An enumeration of key codes that Safari 2 does incorrectly
Code »

Directory events

File Reference