# Keyboard

## core Keyboard

This manager handles all keyboard events. It is a substitute for the keyboard component of EventManager.

## Constructor

#### new Keyboard(options)

Source:
  - core/Keyboard.js, line 45

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`psychoJS` | module:core.PsychoJS |  |  | the PsychoJS instance
`bufferSize` | number | <optional> | `10000` | the maximum size of the circular keyboard event buffer
`waitForStart` | boolean | <optional> | `false` | whether or not to wait for a call to module:core.Keyboard#start before recording keyboard events
`clock` | Clock | <optional> |  | an optional clock
`autoLog` | boolean | <optional> | `false` | whether or not to log

### Extends

- PsychObject

### Members

#### (static, readonly) KeyStatus :Symbol

Source:
  - core/Keyboard.js, line 440

##### Properties:

Name | Type | Description
--- | --- | ---
`KEY_DOWN` | Symbol |
`KEY_UP` | Symbol |

Keyboard KeyStatus.

##### Type:

- Symbol

### Methods

#### (static) includes(keypressList, keyName) → {boolean}

Source:
  - core/Keyboard.js, line 310

Test whether a list of KeyPress's contains one with a particular name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keypressList` | Array.<module:core.KeyPress> | list of KeyPress's
`keyName` | string | pyglet key name, e.g. 'escape', 'left'

##### Returns:

whether or not a KeyPress with the given pyglet key name is present in the list

Type
  boolean

#### (protected) _addKeyListeners()

Source:
  - core/Keyboard.js, line 326

Add key listeners to the document.

#### clearEvents()

Source:
  - core/Keyboard.js, line 291

Clear all events and resets the circular buffers.

#### getEvents() → {Array.<Keyboard.KeyEvent>}

Source:
  - core/Keyboard.js, line 117

Get the list of those keyboard events still in the buffer, i.e. those that have not been previously cleared by calls to getKeys with clear = true.

##### Returns:

the list of events still in the buffer

Type
  Array.<Keyboard.KeyEvent>

#### getKeys(options) → {Array.<KeyPress>}

Source:
  - core/Keyboard.js, line 153

Get the list of keys pressed or pushed by the participant.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`keyList` | Array.<string> | <optional> | `[]` | the list of keys to consider. If keyList is empty, we consider all keys. Note that we use pyglet keys here, to make the PsychoJs code more homogeneous with PsychoPy.
`waitRelease` | boolean | <optional> | `true` | whether or not to include those keys pressed but not released. If waitRelease = false, key presses without a corresponding key release will have an undefined duration.
`clear` | boolean | <optional> | `false` | whether or not to keep in the buffer the key presses or pushes for a subsequent call to getKeys. If a keyList has been given and clear = true, we only remove from the buffer those keys in keyList

##### Returns:

the list of keys that were pressed (keydown followed by keyup) or pushed (keydown with no subsequent keyup at the time getKeys is called).

Type
  Array.<KeyPress>

#### start()

Source:
  - core/Keyboard.js, line 89

Start recording keyboard events.

#### stop()

Source:
  - core/Keyboard.js, line 97

Stop recording keyboard events.

### Type Definitions

#### KeyEvent

Source:
  - core/Keyboard.js, line 102

##### Properties:

Name | Type | Description
--- | --- | ---
`W3C` | string | key code
`W3C` | string | key
`pyglet` | string | key
`key` | module:core.Keyboard#KeyStatus | status
`timestamp` | number | (in seconds)