Keyboard

core Keyboard

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

Constructor

new Keyboard(options)

Source:
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:
Properties:
Name Type Description
KEY_DOWN Symbol
KEY_UP Symbol

Keyboard KeyStatus.

Type:
  • Symbol

Methods

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

Source:

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:

Add key listeners to the document.

clearEvents()

Source:

Clear all events and resets the circular buffers.

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

Source:

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:

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:

Start recording keyboard events.

stop()

Source:

Stop recording keyboard events.

Type Definitions

KeyEvent

Source:
Properties:
Name Type Description
W3C string

key code

W3C string

key

pyglet string

key

key module:core.Keyboard#KeyStatus

status

timestamp number

(in seconds)