API: event YAHOO.util.KeyListener (YUI Library)

# Yahoo! UI Library

### Event Utility 2.9.0

Yahoo! UI Library > event > YAHOO.util.KeyListener
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.util.KeyListener

KeyListener is a utility that provides an easy interface for listening for keydown/keyup events fired against DOM elements.

### Constructor

YAHOO.util.KeyListener `( attachTo , keyData , handler , event )`

Parameters:
  `attachTo <HTMLElement>` The element or element ID to which the key event should be attached
  `attachTo <String>` The element or element ID to which the key event should be attached
  `keyData <Object>` The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).
  `handler <Function>` The CustomEvent handler to fire when the key event is detected
  `handler <Object>` An object literal representing the handler.
  `event <String>` Optional. The event (keydown or keyup) to listen for. Defaults automatically to keydown.

### Properties

#### enabled - `Boolean`

Boolean indicating the enabled/disabled state of the Tooltip

#### KEY - `static final object`

keycode constants for a subset of the special keys

#### YAHOO.util.KeyListener.KEYDOWN - `static final String`

Constant representing the DOM "keydown" event.

#### YAHOO.util.KeyListener.KEYUP - `static final String`

Constant representing the DOM "keyup" event.

### Methods

#### disable

`void disable ( )`
Disables the KeyListener by removing the DOM event listeners from the target DOM element

#### enable

`void enable ( )`
Enables the KeyListener by attaching the DOM event listeners to the target DOM element

#### handleKeyPress

`private void handleKeyPress ( e , obj )`
Handles the key event when a key is pressed.

Parameters:
  `e <DOMEvent>` The keypress DOM event
  `obj <Object>` The DOM event scope object

#### toString

`String toString ( )`
Returns a String representation of the object.

Returns: `String`
  The string representation of the KeyListener

### Events

#### disabledEvent

`disabledEvent ( keyData )`
The CustomEvent fired when the KeyListener is disabled via the disable() function

Parameters:
  `keyData <Object>` The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).

#### enabledEvent

`enabledEvent ( keyData )`
The CustomEvent fired when the KeyListener is enabled via the enable() function

Parameters:
  `keyData <Object>` The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).

#### keyEvent

`private keyEvent ( keyData )`
The CustomEvent fired internally when a key is pressed

Parameters:
  `keyData <Object>` The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).

Copyright © 2011 Yahoo! Inc. All rights reserved.