expyriment.io.Keyboard

class expyriment.io.Keyboard(default_keys=None)[source]

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.

Methods

__init__(default_keys=None)[source]

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)[source]

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()[source]

Clear the event queue from keyboard events.

default_keys

Getter for default keys

static get_pause_key()[source]

Returns the currently defined pause key

static get_quit_key()[source]

Returns the currently defined quit key

logging

Getter for logging.

static process_control_keys(key_event=None)[source]

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.

Returns:

out : bool

True if quitting or pause screen has been displayed, False otherwise

read_out_buffered_keys()[source]

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)[source]

Set the currently defined pause key

static set_quit_key(value)[source]

Set the currently defined quit key

wait(keys=None, duration=None, wait_for_keyup=False, check_for_control_keys=True)[source]

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

check_for_control_keys : bool, optional

checks if control key has been pressed (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, check_for_control_keys=True)[source]

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

check_for_control_keys : bool, optional

checks if control key has been pressed (default=True)

Returns:

found : char

pressed charater

rt : int

reaction time in ms

See also

design.experiment.register_wait_callback_function