# Class: KeyboardHandler

## KeyboardHandler

#### new KeyboardHandler($element, userOptions)

  Handle keyboard typing on an elements

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `$element` | HTMLElement |
  `userOptions` | Object | ###### Properties
  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `selector` | String | <optional> |  | Used for event delegation
  `preventDefault` | Boolean | <optional> | false | Prevent default on all key pressed, except TAB
  `onEnter` | KeyboardHandler_Callback | <optional> |  |
  `onSpace` | KeyboardHandler_Callback | <optional> |  |
  `onSelect` | KeyboardHandler_Callback | <optional> |  | Called when pressing ENTER or SPACE
  `onEscape` | KeyboardHandler_Callback | <optional> |  |
  `onTab` | KeyboardHandler_Callback | <optional> |  |
  `onTabReverse` | KeyboardHandler_Callback | <optional> |  |
  `onRight` | KeyboardHandler_Callback | <optional> |  | Called when pressing RIGHT ARROW KEYS
  `onLeft` | KeyboardHandler_Callback | <optional> |  | Called when pressing LEFT ARROW KEYS
  `onUp` | KeyboardHandler_Callback | <optional> |  | Called when pressing UP ARROW KEYS
  `onDown` | KeyboardHandler_Callback | <optional> |  | Called when pressing DOWN ARROW KEYS
  `onPageUp` | KeyboardHandler_Callback | <optional> |  |
  `onPageDown` | KeyboardHandler_Callback | <optional> |  |
  `onPrevious` | KeyboardHandler_Callback | <optional> |  | Called when pressing LEFT or DOWN arrow keys
  `onNext` | KeyboardHandler_Callback | <optional> |  | Called when pressing RIGHT or UP arrow keys
  `onKey` | KeyboardHandler_Callback | <optional> |  | Called on every key

  See:
    - For more details, see extra/events.md

  ##### Example

      let keyboardControls = new KeyboardHandler( $domElement, options );

      // To cancel events watching
      keyboardControls.off();

### Methods

#### off()

  Remove the binding

  ##### Returns:

  Type
    KeyboardHandler

#### on()

  Add the binding

  ##### Returns:

  Type
    KeyboardHandler

### Type Definitions

#### KeyboardHandler_Callback(event, $context)

  Called when a key is pressed

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `event` | Event |
  `$context` | HTMLElement | Targeted DOM element

#### Search results