PsychoPY version: 2021.2.3, using coder IDE.
OS: Windows 10.
Background: I am getting participants to adjust the height of a rectangular bar by holding down the up or down arrow key. While participant’s change the height of the bar, the bar is also moving horizontally and changing in height independent of the participant’s adjustments.
While this experiment works more often than not, the problem is that randomly on some trials, when participant’s release the key, this key release is not being recognized. As a result, the bar will continuously change its height, as if a participant is adjusting the bar’s height with a key press, even though there is no key press. This adjustment stops when another key is pressed. However, during the remainder of the trial, if I press the key that jammed, the problem resumes.
On some trials, this problem occurs if one of the arrow keys is pressed several times in quick succession.
Unfortunately, I have replicated this problem on 3 different windows 10 machines. On all machines it occurs unpredictably on different conditions and trials.
Attempts at fixing the problem:
Initially, I thought this could be due to framedropping, but interval plots indicate low rates of frame dropping around ~1%.
I initliazed my keyboard with a bufferSize of 0, 1, or 5. But there was no improvements.
I have included my keyboard code below. I deleted from the code the section that changes the bar’s height with participant adjust. Using false and true statements to detect if the key was reported as pressed when it was released, and unfortunately the key-sticking was still occurring.
Finally, I called the keyboard a second time, with waitRelease and Clear set to True. This fixed the problem, but caused significant frame dropping.
keys = kb.getKeys(['up', 'down', 'space'], waitRelease=False, clear=False) #First call #### Code in between ### keys = kb.getKeys(['up', 'down', 'space'], waitRelease=True, clear=True) #Second call
Can anyone help me with this problem? Is this just a random PC limitation?
Many thanks in advance for any assistance anyone can provide.
**Begin routine:** kb = keyboard.Keyboard() #bufferSize kb.clock.reset() #Restart the timer **Each Frame:** keys = kb.getKeys(['up', 'down', 'space'], waitRelease=False, clear=False) if keys and not keys[-1].duration: # resp = keys[-1].name #the last key's name if resp == 'up': noKeyResp = False DownKeyCount -= 1 if Accumulator < 200: Adjust += AdjustmentAmount Accumulator += 1 KeyHistory.append("up") #print('Adjust', Adjust) elif resp == 'down': #'down' in resp: noKeyResp = False if DownKeyCount < 200: #200; This will control how small it gets Adjust -= AdjustmentAmount KeyHistory.append("down") DownKeyCount += 1 elif resp == 'space': #'space' in resp: warning = False noKeyResp = False thisExp.addData('BarAdjustmentAmount', Adjust) DownKeyCount = 0 count = 0 #Reset loopcount once people have pressed the routine Adjust = 0 loopCount = 0 KeyHistory.append("space") thisExp.addData('KeyHistoryTOTAL', KeyHistory) #Save a list of all Keypresses KeyHistory =  thisExp.addData('Adjust', AdjustHistory) AdjustHistory =  BackAdjust = 0 #Reset backadjust if wasprac == 'no': trialcount += 1 thisExp.addData('trialcount', trialcount) kb.clearEvents() #Clear all the keyboard presses to stop issues. continueRoutine = False RepeatTrials.finished = True #End the loop that maintains a continuous rerun Adjust = np.round(Adjust) #Adjust and adjustment amount should be a whole pixel value AdjustHistory.append(Adjust) else: #resp ='placeholder' Accumulator = 0 #As no key is down, it's safe to reset up accumulator, so it is applied