Persistent Keyboard Response Issue Despite Clearing Events and Resetting Variables in PsychoPy 2024.2.4 on macOS 15.1

OS: macOS 15.1

PsychoPy version: 2024.2.4

Standard Standalone? (y/n): Yes

What are you trying to achieve?:

I aim to accurately record keyboard responses during each trial of my experiment. Specifically, I want to ensure that:

  • If a participant presses the correct key, the system registers a correct response.
  • If a participant presses an incorrect key, the system registers an incorrect response.
  • If no key is pressed, the system registers no response.

What did you try to make it work?:

  1. Resetting Keyboard Response Variables: At the beginning of each trial, I reset the keyboard response variables:
task_resp.keys = None
task_resp.corr = None
  1. Clearing Event Queue: I used event.clearEvents() at the start of each trial to clear any residual keypress events:
from psychopy import event
event.clearEvents()
  1. Modifying Key Detection Logic: I adjusted the logic to first check for key presses before evaluating correctness:
result = ''
color = ''
if task_resp.keys:  # Check for keypress
    if task_resp.corr == 1:  # Correct keypress
        result = '✓'
        color = 'green'
    else:  # Incorrect keypress
        result = 'x'
        color = 'red'
else:  # No keypress
    result = 'No response'
    color = 'gray'
  1. Consulting PsychoPy Community Discussions: I referred to the following discussions for potential solutions:

What specifically went wrong when you tried that?:

Despite implementing these solutions, the issue persists:

  • When no key is pressed during a trial, the system incorrectly registers a correct response.
  • In the subsequent trial, even when the correct key is pressed, it registers as incorrect.

There are no error messages displayed; however, the response accuracy is compromised, affecting the integrity of the experiment’s data.

I have also ensured that PsychoPy has the necessary input monitoring permissions on my Mac, as suggested in similar discussions.

I would appreciate any guidance or suggestions to resolve this issue.

Thank you for your assistance.

Here is a minimal demo of my psychopy program
bug.zip (988.3 KB)

To ensure that feedback is presented correctly in PsychoPy Builder, it’s essential to place the Code Component above the Text Component within the same routine. This arrangement ensures that the code executes first, setting the necessary variables, which the Text Component can then display accurately. If the Text Component is placed above the Code Component, it may not display the intended feedback, as the variables it relies on might not be updated in time. For detailed guidance, refer to the PsychoPy documentation on providing feedback:
https://www.psychopy.org/recipes/builderFeedback.html