Recording the time of the start of a screen touch in PsychoPy on Windows

657 views Asked by At

I'm helping to implement an experiment using PsychoPy on a Windows 8 tablet. It doesn't seem to be possible to get direct access to touch events through either PsychoPy, or the pyglet or PyGame interfaces.

Most other sources I've found have referred to using mouse move events in place of touch events. This works fine for recording position, but for recording time it doesn't work for us. We would like to collect the timing of the start of the touch, whereas the mouse event comes at the end of the touch.

Does anyone know of a way to do this, either in PsychoPy or by importing another library into the experiment?

Update: Logging ioHub mouse events, it looks like press and release mouse events are both sent at the end of the touch. This makes sense as this is the point at which the OS is sure that the touch is not a swipe. (Also, it will decide whether the touch is a left- or right-click depending on the duration of the touch).

1

There are 1 answers

0
alisdt On BEST ANSWER

I've managed this using a hook into the WndProc, it's not pretty but it works. The solution, for posterity:

https://github.com/alisdt/pywmtouchhook

A brief summary:

I used a combination of ctypes and pywin32 (unfortunately neither alone could do the job) to register the target HWND to receive touch messages, and replace its WndProc, passing through all non-touch messages to the original WndProc.