KB_02
March 16, 2024, 6:08pm
1
Hi,
I would need some help to record the time between the moment the space bar is pressed and the moment it is released. Participants are required to keep their finger on the space bar before responding, and I would like to measure this duration.
Thanks!
In Builder you can have one routine that ends on a key press and the next one that ends on a key release.
KB_02
March 16, 2024, 7:39pm
3
Thanks, and do you know how implement it with a code?
There are a few possible solutions.
Did a little digging - this is interesting and unintuitive. This code should work if you put it in “Each frame”:
if key_resp.keys:
print(_key_resp_allKeys[-1].duration)
In short the builder is doing a little bit of deceptive magic and hiding the raw output of getKeys by putting it into the keyboard component object, but it skips the duration (which is something that should be looked at for a future version - I don’t have time to make the feature request now but I might later). However, it …
Whoops, sorry! That’s my bad. I copied this from a more complex piece of code that has object structure, the ‘self’ thing I forgot to delete. Drop the ‘self’ altogether from wherever it shows up. Here’s fixed code:
key = pyglet.window.key
keyboard = key.KeyStateHandler()
win.winHandle.push_handlers(keyboard)
if keyboard[key.LEFT]:
BO -= 1
thisExp.addData('adj_final_ori',BO)
if keyboard[key.RIGHT]:
BO += 1
thisExp.addData('adj_final_ori',BO)
EDIT: Also you should put the fi…