psychopy.org | Reference | Downloads | Github

Ignore One Key in Log

We are running an MRI experiment where we want all keypresses to be logged. The task computer also receives input from the scanner, which emulates each new acquisition as a keypress (a ‘5’ is sent many times per second). While we want to use the first ‘5’ to trigger the start of the task (and log the time when this happened), we do not want to write any of the others to the PsychoPy log - it makes the log file extremely long. Is there a way to suppress these ‘5’ keypresses in the log while still logging all other keypresses?

Re-ping! Any suggestions on how to exclude this one key from the log file would be much appreciated!

How many other keys might be pressed during the experiment? Even though it’s really ugly, as long as you can make an exhaustive list, you should be able to use that as the keyList parameter in the code that monitors the keyboard input. So define something like this early on in your code, and use the appropriate list as an event parameter at each stage of the experiment.

keys_start = ['5']
keys_task = ['1','2','3','4','6','7','a','b', ...etc...]

Depending on how your log file is made, including a conditional could prevent ‘5’ input from appearing in the log file, but it might make things slower since it has to be evaluated for every input.

exclude_key = '5'
keys = event.getKeys()

if not exclude_key in keys:
     ...write to log...