psychopy.iohub.client.keyboard.
Keyboard
(ioclient, device_class_name, device_config)¶The Keyboard device provides access to KeyboardPress and KeyboardRelease events as well as the current keyboard state.
state
¶Returns all currently pressed keys as a dictionary of key : time values. The key is taken from the originating press event .key field. The time value is time of the key press event.
Note that any pressed, or active, modifier keys are included in the return value.
Returns: | dict |
---|
reporting
¶By default, the Keyboard starts reporting events automatically when the ioHub process is started and continues to do so until the process is stopped.
This property can be used to read or set the device reporting state:
# Read the reporting state of the keyboard.
is_reporting_keyboard_event = keyboard.reporting
# Stop the keyboard from reporting any new events.
keyboard.reporting = False
getKeys
(keys=None, chars=None, mods=None, duration=None, etype=None, clear=True)¶Return a list of any KeyboardPress or KeyboardRelease events that have occurred since the last time either:
Other than the ‘clear’ kwarg, any non None or empty list kwargs passed to the method filter the possible events that can be returned using the keyboard event field with the associated name.
If multiple filter criteria are provided, only events that match all specified criteria are returned.
If no KeyboardEvent’s are found that match the filtering criteria, an empty tuple is returned.
Returned events are sorted by time.
Parameters: |
|
---|---|
Returns: | tuple of KeyboardEvent instances, or () |
getPresses
(keys=None, chars=None, mods=None, clear=True)¶See the getKeys() method documentation. This method is identical, but only returns KeyboardPress events.
getReleases
(keys=None, chars=None, mods=None, duration=None, clear=True)¶See the getKeys() method documentation. This method is identical, but only returns KeyboardRelease events.
waitForKeys
(maxWait=None, keys=None, chars=None, mods=None, duration=None, etype=None, clear=True, checkInterval=0.002)¶Blocks experiment execution until at least one matching KeyboardEvent occurs, or until maxWait seconds has passed since the method was called.
Keyboard events are filtered using any non None kwargs values in the same way as the getKeys() method. See getKeys() for a description of the arguments shared between the two methods.
As soon as at least one matching KeyboardEvent occur prior to maxWait, the matching events are returned as a tuple.
Parameters: |
|
---|
waitForPresses
(maxWait=None, keys=None, chars=None, mods=None, duration=None, clear=True, checkInterval=0.002)¶See the waitForKeys() method documentation. This method is identical, but only returns KeyboardPress events.
getName
()¶Gets the name given to the device in the ioHub configuration file. ( the device: name: property )
waitForReleases
(maxWait=None, keys=None, chars=None, mods=None, duration=None, clear=True, checkInterval=0.002)¶See the waitForKeys() method documentation. This method is identical, but only returns KeyboardRelease events.
The Keyboard device can return two types of events, which represent key press and key release actions on the keyboard.
psychopy.iohub.client.keyboard.
KeyboardPress
(ioe_array)¶An iohub Keyboard device key press event.
char
¶The unicode value of the keyboard event, if available. This field is only populated when the keyboard event results in a character that could be printable.
Returns: | unicode, ‘’ if no char value is available for the event. |
---|
modifiers
¶A list of any modifier keys that were pressed when this keyboard event occurred. Each element of the list contains a keyboard modifier string constant. Possible values are:
If no modifiers were active when the event occurred, an empty list is returned.
Returns: | tuple |
---|
time
¶The time stamp of the event, in the same time base that is used by psychopy.core.getTime()
Returns: | float |
---|
type
¶The string type constant for the event.
Returns: | str |
---|
psychopy.iohub.client.keyboard.
KeyboardRelease
(ioe_array)¶An iohub Keyboard device key release event.
duration
¶The duration (in seconds) of the key press. This is calculated by subtracting the current event.time from the associated keypress.time.
If no matching keypress event was reported prior to this event, then 0.0 is returned. This can happen, for example, when the key was pressed prior to psychopy starting to monitor the device. This condition can also happen when keyboard.reset() method is called between the press and release event times.
Returns: | float |
---|
pressEventID
¶The event.id of the associated press event.
The key press id is 0 if no associated KeyboardPress event was found. See the duration property documentation for details on when this can occur.
Returns: | unsigned int |
---|
char
¶The unicode value of the keyboard event, if available. This field is only populated when the keyboard event results in a character that could be printable.
Returns: | unicode, ‘’ if no char value is available for the event. |
---|
id
¶The unique id for the event; sometimes used to track associated events.
Returns: | int |
---|
modifiers
¶A list of any modifier keys that were pressed when this keyboard event occurred. Each element of the list contains a keyboard modifier string constant. Possible values are:
If no modifiers were active when the event occurred, an empty list is returned.
Returns: | tuple |
---|
time
¶The time stamp of the event, in the same time base that is used by psychopy.core.getTime()
Returns: | float |
---|
type
¶The string type constant for the event.
Returns: | str |
---|