expyriment.io.Keyboard¶
-
class
expyriment.io.
Keyboard
(default_keys=None)¶ A class implementing a keyboard input.
Calling expyriment.control.initialize(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!
-
clear
()¶ Clear the event queue from keyboard events.
-
property
default_keys
¶ Getter for default keys
-
static
get_pause_key
()¶ Returns the currently defined pause key
-
static
get_quit_key
()¶ Returns the currently defined quit key
-
property
logging
¶ Getter for logging.
-
static
process_control_keys
(key_event=None, quit_confirmed_function=None)¶ Check if quit_key or pause_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.
- quit_confirmed_functionfunction, optional
function to be called if quitting has been confirmed.
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)
-
static
set_pause_key
(value)¶ Set the currently defined pause key
-
static
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)¶ 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)
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)¶ 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)
Returns: - foundchar
pressed character
- rtint
reaction time in ms
-