Class: Keyboard

core.Keyboard(options)

new Keyboard(options)

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

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
Source:

Members

(readonly) KeyStatus :Symbol

Keyboard KeyStatus.
Type:
  • Symbol
Source:

Methods

(private) _addKeyListeners()

Add key listeners to the document.
Source:

clearEvents()

Clear all events and resets the circular buffers.
Source:

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

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.
Source:
Returns:
the list of events still in the buffer
Type
Array.<Keyboard.KeyEvent>

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

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
Source:
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>

includes(keypressList, keyName) → {boolean}

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'
Source:
Returns:
whether or not a KeyPress with the given pyglet key name is present in the list
Type
boolean

start()

Start recording keyboard events.
Source:

stop()

Stop recording keyboard events.
Source: