expyriment.io.Keyboard
- class expyriment.io.Keyboard(default_keys=None)
A class implementing a keyboard input.
Calling expyriment.control.initialise(exp) will automatically create a keyboard instance and will reference it in exp.keyboard for easy access.
- __init__(default_keys=None)
Create a keyboard input.
- Parameters:
- default_keysint or list, optional
a default key or list of default keys
- check(keys=None, check_for_keyup=False, check_for_control_keys=True)
Check if keypress is in event queue.
- Parameters:
- keysint or list, optional
a specific key or list of keys to check
- check_for_keyupbool, optional
if True checks for key-up (default = False)
- check_for_control_keysbool, optional
checks if control key has been pressed (default = True)
- Returns:
- keyint
pressed key or None. Only the first occurrence is returned!
Notes
Keys are defined by keyboard constants (please see misc.constants).
When checking for key-down (default), all key-up events are first cleared, and when checking for key-up events, all key-down events are first cleared!
Unlike the wait method, events are only logged on loglevel 2 when no keys are specified. this is to prevent excessive default logging when used repeatedly in a loop.
- clear()
Clear the event queue from keyboard events.
- property default_keys
Getter for default keys
- classmethod get_quit_key()
Returns the currently defined quit key
- property logging
Getter for logging.
- classmethod process_control_keys(key_event=None, event_detected_function=None, quit_confirmed_function=None, quit_denied_function=None)
Check if quit_key has been pressed.
Reads pygame event cue if no key_event is specified.
- Parameters:
- key_eventint, optional
key event to check. If not defined, the Pygame event queue will be checked for key down events.
- event_detected_functionfunction, optional
function to be called when key event is detected.
- quit_confirmed_functionfunction, optional
function to be called if quitting has been confirmed.
- quit_denied_functionfunction, optional
function to be called if quitting has been denied.
- Returns:
- outbool
True if quitting or pause screen has been displayed, False otherwise
- read_out_buffered_keys()
Reads out all keydown events and clears queue.
- set_logging(onoff)
Set logging of this object on or off
- Parameters:
- onoffbool
set logging on (True) or off (False)
- classmethod set_quit_key(value)
Set the currently defined quit key
- wait(keys=None, duration=None, wait_for_keyup=False, callback_function=None, process_control_events=True, low_performance=False)
Wait for keypress(es) (optionally for a certain amount of time).
This function will wait for a keypress and returns the found key as well as the reaction time. (This function clears the event queue!)
- Parameters:
- keysint or list, optional
a specific key or list of keys to wait for
- durationint, optional
maximal time to wait in ms
- wait_for_keyupbool, optional
if True it waits for key-up (default=False)
- callback_functionfunction, optional
function to repeatedly execute during waiting loop
- process_control_eventsbool, optional
process
io.Keyboard.process_control_keys()
andio.Mouse.process_quit_event()
(default = True)- low_performancebool, optional
reduce CPU performance (and allow potential threads to run) while waiting at the cost of less timing accuracy (default = False)
- Returns:
- foundchar
pressed character
- rtint
reaction time in ms
Notes
Keys are defined by keyboard constants (please see misc.constants).
- wait_char(char, duration=None, callback_function=None, process_control_events=True, low_performance=False)
Wait for character(s) (optionally for a certain amount of time).
This function will wait for one or more characters and returns the found character as well as the reaction time. (This function clears the event queue!)
- Parameters:
- charint or list
a specific character or list of characters to wait for
- durationint, optional
maximal time to wait in ms
- callback_functionfunction, optional
function to repeatedly execute during waiting loop
- process_control_eventsbool, optional
process
io.Keyboard.process_control_keys()
andio.Mouse.process_quit_event()
(default = True)- low_performancebool, optional
reduce CPU performance (and allow potential threads to run) while waiting at the cost of less timing accuracy (default = False)
- Returns:
- foundchar
pressed character
- rtint
reaction time in ms