Capturing event times during StaticPeriod

I’m trying to capture event times (specifically keyboard events occurring every ~1.5s) that occur during a static component (clock.StaticPeriod). After the period, I am able to collect the events from the buffer, but the event times are inaccurate: they’re all within milliseconds from each other and align to the end of the period.

My question is whether I can capture event times for events that occur during a StaticPeriod? Note that I do not need access to these events during the period.

The application is that during an fMRI experiment, I collect the onset times of each imaging volume. The scanner sends a sync pulse that I transform to a USB keyboard input, for which I listen as a keyboard event in psychopy. Separately, I load images during certain down times in the experiment (a process that takes some time), and am currently using StaticPeriod to allow the clock to advance while I load these images so as to avoid delays. Of course, the scanner is sending the sync pulses continuously, including during these periods, and I’m attempting to capture them with getKeys(), but the timestamps are inaccurate (as described above). Is there a way I can get the desired functionality in psychopy? (Some other programs would allow an “asynchronous loop” – it seemed that StaticPeriod was the closest thing to this functionality, but perhaps there’s another way…?)

Thanks very much!

Using the standard PsychoPy event module, the time of a key or mouse press is the time that you check for it. If you haven’t checked for some time, the actual keypress may have occurred several seconds ago (during the static period, for example), but the reaction time will be the current time.

Generally this checking is done in a tight loop, so this isn’t an issue. But you’re using a static period correctly to counter delays due to image loading that would impact on such a loop. So the best alternative for you would be to look into using the ioHub module, which does allow asynchronous response collection. The response is time-stamped with the time at which it occurred, not the time you call the function to collect it.

Thanks, Michael.
I’ve been trying to use ioHub, but having difficulty getting it to report anything other than modifier key presses. Apparently, others have had this problem, but their solution (reinstalling psychopy) didn’t work for me. See thread: ioHub getKeys() only logging modifier keys

Do you have any suggestions?

Thanks very much,
Daniel

SOLVED:
By adding the terminal app to the Mac OS accessibility list, iohub now registers all key presses.
see: http://mizage.com/help/accessibility.html#10.9

Thanks!
Daniel

1 Like

Well done. Yes that is the special technique ioHub uses in order to intercept keypresses meant for any window. This needs to be stated more clearly in the online documentation perhaps.

Using the standard PsychoPy event module, the time of a key or mouse press is the time that you check for it. If you haven’t checked for some time, the actual keypress may have occurred several seconds ago (during the static period, for example), but the reaction time will be the current time.

That’s a non-obvious behavior that should in the API’s documentation.

You are welcome to suggest changes to the documentation via a pull request at GitHub.