events.KeyHandler Extends goog.events.EventTarget
A wrapper around an element that you want to listen to keyboard events on.

Inheritance

Constructor

goog.events.KeyHandler(opt_elementopt_capture)

Parameters

opt_element :
(Document | Element | null | undefined)
The element or document to listen on.
opt_capture :
(boolean | undefined)
Whether to listen for browser events in capture phase (defaults to false).

Instance Methods

Public Protected Private
attach(elementopt_capture)
Adds the proper key event listeners to the element.
Arguments:
element :
(Document | Element | null)
The element to listen on.
opt_capture :
(boolean | undefined)
Whether to listen for browser events in capture phase (defaults to false).
code »
detach()
Removes the listeners that may exist.
code »
disposeInternal()
No description.
code »
getElement()
(Document | Element | null)
Returns the element listened on for the real keyboard events.
Returns: 
(Document | Element | null)
  The element listened on for the real keyboard events.
code »
handleEvent(e)
Handles the events on the element.
Arguments:
e :
The keyboard event sent from the browser.
code »
handleKeyDown_(e)
Records the keycode for browsers that only returns the keycode for key up/ down events. For browser/key combinations that doesn't trigger a key pressed event it also fires the patched key event.
Arguments:
e :
The key down event.
code »
handleKeyup_(e)
Clears the stored previous key value, resetting the key repeat status. Uses -1 because the Safari 3 Windows beta reports 0 for certain keys (like Home and End.)
Arguments:
e :
The keyup event.
code »
addEventListener(typehandleropt_captureopt_handlerScope)
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. Supported for legacy but use goog.events.listen(src, type, handler) instead.
Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
code »
dispatchEvent(e)
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Arguments:
e :
(Object | goog.events.Event | null | string)
Event object.
Returns:   If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.
code »
disposeInternal()
Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:
MyClass.prototype.disposeInternal = function() {
MyClass.superClass_.disposeInternal.call(this);
// Dispose logic for MyClass
};
code »
getParentEventTarget()
Returns the parent of this event target to use for bubbling.
Returns:   The parent EventTarget or null if there is no parent.
code »
removeEventListener(typehandleropt_captureopt_handlerScope)
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture :
(boolean | undefined)
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for bubbling.
Arguments:
parent :
Parent EventTarget (null if none).
code »
dispose()
undefined
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: 
undefined
  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
mypackage.MyClass = function() {
goog.base(this);
// Constructor logic specific to MyClass.
...
};
goog.inherits(mypackage.MyClass, goog.Disposable);

mypackage.MyClass.prototype.disposeInternal = function() {
goog.base(this, 'disposeInternal');
// Dispose logic specific to MyClass.
...
};
code »
getDisposed()
Use #isDisposed instead. No description.
Returns:   Whether the object has been disposed of.
code »
isDisposed()
No description.
Returns:   Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable :
that will be disposed when this object is disposed.
code »

Instance Properties

element_ :
(Document | Element | null)
This is the element that we will listen to the real keyboard events on.
Code »
keyCode_ :
Keycode recorded for key down events. As most browsers don't report the keycode in the key press event we need to record it in the key down phase.
Code »
keyDownKey_ :
(null | number)
The key for the key down listener.
Code »
keyPressKey_ :
(null | number)
The key for the key press listener.
Code »
keyUpKey_ :
(null | number)
The key for the key up listener.
Code »
lastKey_ :
Used to detect keyboard repeat events.
Code »
customEvent_ :
Used to tell if an event is a real event in goog.events.listen() so we don't get listen() calling addEventListener() and vice-versa.
Code »
parentEventTarget_ :
Parent event target, used during event bubbling.
Code »
dependentDisposables_ :
(Array | null)
Disposables that should be disposed when this object is disposed.
Code »
disposed_ :
Whether the object has been disposed of.
Code »

Static Properties

goog.events.KeyHandler.USES_KEYDOWN_ :
If true, the KeyEvent fires on keydown. Otherwise, it fires on keypress.
Code »
goog.events.KeyHandler.keyIdentifier_ :
(Object | null)
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_ :
(Object | null)
Map from Gecko specific key codes to cross browser key codes
Code »
goog.events.KeyHandler.safariKey_ :
(Object | null)
An enumeration of key codes that Safari 2 does incorrectly
Code »

Enumerations

goog.events.KeyHandler.EventType :
Enum type for the events fired by the key handler
Constants:
KEY
No description.
Code »

Package events

Package Reference