stimuli.keyboard.Keyboard🔗
- class stimuli.keyboard.Keyboard(keys=None, *, clock=<class 'stimuli.time._clock.Clock'>, on_press=None, on_release=None)[source]🔗
Object monitoring inputs on the keyboard.
- Parameters:
- keys
str
|list
ofstr
|None
The list of keys to monitor. If None, all keys will be monitored. Keys should be specified as strings, for instance
['a', 'enter', 'space', 'shift_r']
.- clock
stimuli.time.BaseClock
class Clock object to use for timing measurements. By default, the
stimuli.time.Clock
class is used.- on_press
callable()
|None
Additional callback function to call on a button press. The function should have the signature
callback(key: KeyCode | Key | None)
where key isNone
if the key is unknown orKeyCode
orKey
otherwise.- on_release
callable()
|None
Additional callback function to call on a button release. The function should have the signature
callback(key: KeyCode | Key | None)
where key isNone
if the key is unknown orKeyCode
orKey
otherwise.
- keys
Attributes
The time of instantiation of the Keyboard in seconds.
Methods
get_keys
()Get a list of keys that were pressed since the last call.
reset
()Reset the clock and events of the Keyboard.
start
(*[, suppress])Start monitoring the keyboard.
stop
()Stop monitoring the keyboard.
wait_keys
(*[, timeout])Wait until a key is pressed.
- get_keys()[source]🔗
Get a list of keys that were pressed since the last call.
- Returns:
- keys
list
ofstimuli.keyboard.KeyEvent
|None
The list of keys that were pressed. If the keyboard is not running, None is returned.
- keys
Notes
Note that calling this method will reset the buffer.
- wait_keys(*, timeout=None)[source]🔗
Wait until a key is pressed.
- Parameters:
- Returns:
- key
stimuli.keyboard.KeyEvent
|None
The key that was pressed or None if the timeout was reached.
- key