-
Notifications
You must be signed in to change notification settings - Fork 21
/
ppc2_iohub_compareToEvent.py
39 lines (33 loc) · 1.21 KB
/
ppc2_iohub_compareToEvent.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
# -*- coding: utf-8 -*-
"""
Demonstrate iohub module versus event module with a flip-loop.
iohub registers responses during win.flip(), thus always scores
responses as faster than event.getKeys() which timestamps according
to the time that the function is called.
Jonas Kristoffer Lindeløv, 2015.
"""
import psychopy
psychopy.useVersion('1.81.02')
from psychopy import iohub, visual, event
win = visual.Window()
textStim = visual.TextStim(win, text='press now', height=0.1, wrapWidth=100)
io = iohub.launchHubServer()
keyboard = io.devices.keyboard
# Comparing iohub.
while True:
# Animate and show results
textStim.ori += 0.1
textStim.draw()
win.flip()
# Get responses
event_getkeys = event.getKeys(timeStamped=True)
io_getpresses = keyboard.getPresses()
# Update text if a matching response was found
if len(event_getkeys) and len(io_getpresses):
textStim.text = """
event.getKeys time: %.3f s
iohub.getPresses time: %.3f s
io time is %i ms before event
""" %(event_getkeys[0][1], io_getpresses[0].time, 1000*(event_getkeys[0][1] - io_getpresses[0].time))
if io_getpresses[0].char == 'q':
break