expyriment.io.Keyboard¶
-
class
expyriment.io.
Keyboard
(default_keys=None)¶ A class implementing a keyboard input.
Calling expyriment.control.intialize(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_keys : int or list, optional
a default key or list of default keys
-
check
(keys=None, check_for_control_keys=True)¶ Check if keypress is in event queue.
Parameters: keys : int or list, optional
a specific key or list of keys to check
check_for_control_keys : bool, optional
checks if control key has been pressed (default = True)
Returns: key : int
pressed key or None. Only the first occurence is returned!
-
clear
()¶ Clear the event queue from keyboard events.
-
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
-
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_event : int, optional
key event to check. If not defined, the Pygame event queue will be checked for key down events.
quit_confirmed_function : function, optional
function to be called if quitting has been confirmed.
Returns: out : bool
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: onoff : bool
set logging on (True) or off (False)
Notes
See also design.experiment.set_log_level fur further information about event logging.
-
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: keys : int or list, optional
a specific key or list of keys to wait for
duration : int, optional
maximal time to wait in ms
wait_for_keyup : bool, optional
if True it waits for key-up
callback_function : function, optional
function to repeatedly execute during waiting loop
process_control_events : bool, optional
process
io.Keyboard.process_control_keys()
andio.Mouse.process_quit_event()
(default = True)Returns: found : char
pressed character
rt : int
reaction time in ms
See also
design.experiment.register_wait_callback_function
Notes
Keys are defined my keyboard constants (please use 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: char : int or list
a specific character or list of characters to wait for
duration : int, optional
maximal time to wait in ms
callback_function : function, optional
function to repeatedly execute during waiting loop
process_control_events : bool, optional
process
io.Keyboard.process_control_keys()
andio.Mouse.process_quit_event()
(default = True)Returns: found : char
pressed character
rt : int
reaction time in ms
See also
design.experiment.register_wait_callback_function
-