[solved] How to log the duration of a key press?
Hello!
I've trying OS for less than a week, done the tutorial and would like to start making my own experiments in this platform, I used to use the psychophysics toolbox for matlab, wich was good, but pretty complicated to run under linux....
My question is:
How can I log the duration of a keypress, not just when it was pressed but for how long?
Thanks,
Good Look!
Comments
Hi Mtoro,
Welcome to the forum!
Yes, that's possible. But you will need to refer directly to the libraries used by the back-end, because the openexp.keyboard module doesn't support "key up" functionality (I'll consider adding it, because it would be useful. So thanks for bringing this to my attention!)
For the pygame-based back-ends (legacy and opengl) the following piece of inline_script should do the trick (so you would use an inline_script rather than a keyboard_response to collect responses):
import pygame from pygame.locals import * key_down_time = None while key_down_time == None: for event in pygame.event.get(): if event.type == KEYDOWN: key_down_time = self.time() break key_up_time = None while key_up_time == None: for event in pygame.event.get(): if event.type == KEYUP: key_up_time = self.time() break key_duration = key_up_time - key_down_time self.experiment.set("key_duration", key_duration)You can modify this inline_script to fit your particular needs, but at least it shows how to determine the duration (uptime - downtime) for a keypress.
For more information, you can refer to the pygame documentation:
http://www.pygame.org/docs/ref/event.html
For doing the same trick with the psychopy back-end, please refer to the psychopy documentation:
http://www.psychopy.org/api/event.html
Hope this helps!
Kindest regards,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Many Thanks for the Answer!!
Will try it monday and comment on the results,
Great Job for OS,
Hope you have a good time!
Mauricio.
Inactive, marking as solved.
Check out SigmundAI.eu for our OpenSesame AI assistant!