# EventManager

## core EventManager

This manager handles all participant interactions with the experiment, i.e. keyboard, mouse and touch events.

## Constructor

#### new EventManager(psychoJS, psychoJS)

Source:
  - core/EventManager.js, line 16

##### Parameters:

Name | Type | Description
--- | --- | ---
`psychoJS` | Object |
`psychoJS` | module:core.PsychoJS | the PsychoJS instance

### Members

#### (protected, static, readonly) _keycodeMap :Object.<number, String>

Source:
  - core/EventManager.js, line 394

This map provides support for browsers that have not yet adopted the W3C KeyboardEvent.code standard for detecting key presses. It maps the deprecated KeyboardEvent.keycode values to the W3C UI event codes.

Unfortunately, it is not very fine-grained: for instance, there is no difference between Alt Left and Alt Right, or between Enter and Numpad Enter. Use at your own risk (or upgrade your browser...).

##### Type:

- Object.<number, String>

#### (protected, static, readonly) _pygletMap :Object.<String, String>

Source:
  - core/EventManager.js, line 481

This map associates pyglet key names to the corresponding W3C KeyboardEvent codes values.

More information can be found `here`

##### Type:

- Object.<String, String>

#### (protected, static, readonly) _reversePygletMap :Object.<String, String>

Source:
  - core/EventManager.js, line 581

This map associates W3C KeyboardEvent.codes to the corresponding pyglet key names.

##### Type:

- Object.<String, String>

### Methods

#### (static) keycode2w3c(keycode) → {string}

Source:
  - core/EventManager.js, line 376

Convert a keycode to a W3C UI Event code.

This is for legacy browsers.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keycode` | number | the keycode

##### Returns:

corresponding W3C UI Event code

Type
  string

#### (static) pyglet2w3c(pygletKeyList) → {Array.string}

Source:
  - core/EventManager.js, line 333

Convert a keylist that uses pyglet key names to one that uses W3C KeyboardEvent.code values.

This allows key lists that work in the builder environment to work in psychoJS web experiments.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pygletKeyList` | Array.string | the array of pyglet key names

##### Returns:

the w3c keyList

Type
  Array.string

#### (static) w3c2pyglet(code) → {string}

Source:
  - core/EventManager.js, line 357

Convert a W3C Key Code into a pyglet key.

##### Parameters:

Name | Type | Description
--- | --- | ---
`code` | string | W3C Key Code

##### Returns:

corresponding pyglet key

Type
  string

#### (protected) _addKeyListeners()

Source:
  - core/EventManager.js, line 294

Add key listeners to the document.

#### addMouseListeners(renderer)

Source:
  - core/EventManager.js, line 193

Add various mouse listeners to the Pixi renderer of the `Window`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`renderer` | PIXI.Renderer | The Pixi renderer

#### clearEvents()

Source:
  - core/EventManager.js, line 148
To Do:
  - handle the attribs argument

Clear all events from the event buffer.

#### clearKeys()

Source:
  - core/EventManager.js, line 156

Clear all keys from the key buffer.

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

Source:
  - core/EventManager.js, line 64

Get the list of keys pressed by the participant.

Note: The w3c `key-event viewer` can be used to see possible values for the items in the keyList given the user's keyboard and chosen layout. The "key" and "code" columns in the UI Events fields are the relevant values for the keyList argument.

##### Parameters:

Name | Type | Description
--- | --- | ---

`options`

Object

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`keyList` | Array.<string> | <optional> | `null` | keyList allows the user to specify a set of keys to check for. Only keypresses from this set of keys will be removed from the keyboard buffer. If no keyList is given, all keys will be checked and the key buffer will be cleared completely.
`timeStamped` | boolean | <optional> | `false` | If true will return a list of tuples instead of a list of keynames. Each tuple has (keyname, time).

##### Returns:

the list of keys that were pressed.

Type
  Array.<string>

#### getMouseInfo() → {EventManager.MouseInfo}

Source:
  - core/EventManager.js, line 138

Get the mouse info.

##### Returns:

the mouse info.

Type
  EventManager.MouseInfo

#### resetMoveClock()

Source:
  - core/EventManager.js, line 184
To Do:
  - not implemented

Reset the move clock.

#### startMoveClock()

Source:
  - core/EventManager.js, line 166
To Do:
  - not implemented

Start the move clock.

#### stopMoveClock()

Source:
  - core/EventManager.js, line 175
To Do:
  - not implemented

Stop the move clock.

### Type Definitions

#### ButtonInfo

Source:
  - core/EventManager.js, line 119

##### Properties:

Name | Type | Description
--- | --- | ---
`pressed` | Array.number | the status of each mouse button [left, center, right]: 1 for pressed, 0 for released
`clocks` | Array.Clock | the clocks associated to the mouse buttons, reset whenever the button is pressed
`times` | Array.number | the time elapsed since the last rest of the associated clock

#### MouseInfo

Source:
  - core/EventManager.js, line 126

##### Properties:

Name | Type | Description
--- | --- | ---
`pos` | Array.number | the position of the mouse [x, y]
`wheelRel` | Array.number | the relative position of the wheel [x, y]
`buttons` | EventManager.ButtonInfo | the mouse button info
`moveClock` | Clock | the clock that is reset whenever the mouse moves