-
Notifications
You must be signed in to change notification settings - Fork 21
/
ppc2_iohub_INPROGRESS.py
72 lines (54 loc) · 2.04 KB
/
ppc2_iohub_INPROGRESS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
This is a small demo on using iohub to capture keyboard and mouse responses.
psychopy.iohub can be used to replace psychopy.event
psychopy.iohub is superior to psychopy.event in the following ways:
* Listen for input while the main python session is busy with stimuli.
This is good for timing!
* Listen for keyboard releases and currently pressed keys.
* Easily capture combinations of keys and the characters they return.
NOTE: If you're running Mac OS, you may need to elevate psychoopy's permissions
for iohub to work properly. Otherwise it will only capture moderator keys.
Drag-drop psychopy into the Accessibility: http://kb.parallels.com/en/116418.
Jonas Kristoffer Lindeløv, 2014. Revised 2015.
"""
# Initiate keyboard
from psychopy import iohub
io = iohub.launchHubServer()
keyboard = io.devices.keyboard
# WAITING FOR KEYBOARD
print 'Listening now...'
keyboard.waitForKeys(chars=['@', '!'])
print 'key event!'
print keyboard.state # print keyboard state
keyboard.waitForReleases(keys=['f'], mods=['lalt', 'ralt'])
print 'key release!'
keyboard.waitForPresses(chars=['F', '@', '!'])
print 'key press!'
"""
EXERCISE:
* Make a small script that waits until the subject has
written 'Dawg!'
Hint: (D, a, w, g, !).
* Now start a psychopy Window with a TextStim that updates to show
this in text, as if one was typing in a text field.
(Maybe the text should turn green upon success?)
* Pro: use keyboard.state to determine if the subject is currently
holding down a, s, d, f, and g.
Hint: dict.keys() and set(lista) == set(listb)
"""
io.wait(1)
io.clearEvents('all')
print 'listening now!'
# iohub wait* methods above are identical to doing this, although they do
# it in a different process than the main python session:
while True:
events = keyboard.getEvents(iohub.EventConstants.KEYBOARD_RELEASE) # listening for releases
if events: # if non-empty
break
print 'finish'
"""
TO DO:
* GETTING KEYBOARD RESPONSE DURING FLIP-LOOP.
* MOUSE STUFF
"""