3 ways to get keyboard input - which is best?

Jonathan is right, but I’d go further and advocate use of psychopy.hardware.keyboard over psychopy.event, and effectively regard the latter as deprecated (at least for keypress handling - it can still be used for dealing with mice).

Keyboard is as easy to use as the event module, but its performance is far better. It will perform similarly to ioHub, but be easier to use (partly because ioHub can do so many other things as well).

Of most relevance to most people is that the response time associated with a keypress is now the time the key was actually pressed, not the time you checked it. The latter is how the event module works, which is not obvious to people, and is why reaction times tend to have a 16 ms granularity in many scripts, if a call to event.getKeys() is made only once per screen refresh. Keyboard.getKeys() can be called on the same schedule (or even less frequently), and still give you the actual time of the keypress, because, a bit like ioHub, the checking is happening in a separate process from the main PsychoPy process.

The docs explain the differences here, and note that the Keyboard object effectively replaces the event module for keypress handling:

https://www.psychopy.org/api/hardware/keyboard.html#psychtoolbox-versus-event-getkeys

One limitation, though, is that there doesn’t seem to be a .waitKeys() function written for it yet (although a user can implement that themselves just be calling Keyboard.getKeys() in a loop).

2 Likes