Print Friendly

# Class YAHOO.util.KeyListener

Package: | YAHOO.util
Class: | KeyListener
Extends: | Object
Defined In: | container_core.js

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

## Public Properties

Property | Defined By
--- | ---
| KEYDOWN<static> : String | KeyListener
<static> Constant representing the DOM "keydown" event.
| KEYUP<static> : String | KeyListener
<static> Constant representing the DOM "keyup" event.
| enabled : Boolean | KeyListener
Boolean indicating the enabled/disabled state of the Tooltip

## Public Methods

Method | Defined By
--- | ---
| KeyListener(`HTMLElement attachTo`, `String attachTo`, `Object keyData`, `Function handler`, `Object handler`, `String event`) | KeyListener
| disable() : void | KeyListener
Disables the KeyListener by removing the DOM event listeners from the target DOM element
| enable() : void | KeyListener
Enables the KeyListener by attaching the DOM event listeners to the target DOM element
| toString() : String | KeyListener
Returns a String representation of the object.

## Public Events

Event | Defined By
--- | ---
| disabledEvent : (`Object keyData`) | KeyListener
The CustomEvent fired when the KeyListener is disabled via the disable() function
| enabledEvent : (`Object keyData`) | KeyListener
The CustomEvent fired when the KeyListener is enabled via the enable() function

## Property Details

### KEYDOWN<static>

`public String KEYDOWN<static>`
<static> Constant representing the DOM "keydown" event.
This property is defined by KeyListener.

### KEYUP<static>

`public String KEYUP<static>`
<static> Constant representing the DOM "keyup" event.
This property is defined by KeyListener.

### enabled

`public Boolean enabled`
Boolean indicating the enabled/disabled state of the Tooltip
This property is defined by KeyListener.

## Constructor Details

### KeyListener

`public function KeyListener(`HTMLElement attachTo`, `String attachTo`, `Object keyData`, `Function handler`, `Object handler`, `String 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.

## Method Details

### disable

`public function disable()`
Disables the KeyListener by removing the DOM event listeners from the target DOM element
Parameters:

- None.

Returns:

- `void`

This method is defined by KeyListener.

### enable

`public function enable()`
Enables the KeyListener by attaching the DOM event listeners to the target DOM element
Parameters:

- None.

Returns:

- `void`

This method is defined by KeyListener.

### toString

`public function toString()`
Returns a String representation of the object.
Parameters:

- None.

Returns:

- `String`
  The string representation of the KeyListener

This method is defined by KeyListener.

## Event Details

### disabledEvent

`public event disabledEvent`
The CustomEvent fired when the KeyListener is disabled via the disable() function
Subscribers will be called with the following 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).

This event is defined by KeyListener.

### enabledEvent

`public event enabledEvent`
The CustomEvent fired when the KeyListener is enabled via the enable() function
Subscribers will be called with the following 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).

This event is defined by KeyListener.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.