generated from mscheltienne/template-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mathieu Scheltienne
committed
Dec 3, 2024
1 parent
2a73da2
commit e6fc8cf
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.. include:: ../links.inc | ||
|
||
Keyboard | ||
-------- | ||
|
||
To interact with the keyboard during an experiment, you can use a | ||
:class:`~stimuli.keyboard.Keyboard` object which monitors in a separate thread for key | ||
inputs. | ||
|
||
.. curentmodule:: stimuli.keyboard | ||
|
||
.. autosummary:: | ||
:toctree: ../generated/api | ||
|
||
Keyboard | ||
KeyEvent | ||
|
||
Example usage:: | ||
|
||
from stimuli.keyboard import Keyboard | ||
from stimuli.time import sleep | ||
|
||
|
||
kb = Keyboard(keys=["esc", "space"]).start(suppress=True) | ||
while True: | ||
events = kb.get_keys() | ||
if any(event.key == "esc" for event in events): | ||
print("Escape key pressed") | ||
break | ||
spaces = [event.key == "space" for event in events] | ||
print(f"Space bar pressed {spaces.count(True)} times in the last 500 ms.") | ||
sleep(0.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters