I have a routine that is repeated 5 times using a loop. The routine ends when either the left or right button is clicked. I used this code in the every frame tab:
clicks = mouse.getPressed()
if clicks[0] or clicks[2]:
continueRoutine = False
At first, there is a feedback routine after this mouse routine and the previously clicked button is not dragged to the next trial. However when I remove that feedback routine a click in the first repetition will be dragged and take as answers in the following 4 repetitions.
How can I manually clear the pressed buttons? Or alternatively, how can I delay the start of the next trial until the mouse resets?
I forgot to say that is an online experiment. Anyway, I tried it and it didin’t work (I had this already: event=psychoJS.eventManager;):
event.clearEvents(eventType='mouse')
and event.clearEvents()
I had the idea that clearEvents() works only the keyboard.
Anyway, the problem is the following. Imagine you have one routine you repeat 5 times, the problem is that your answer in the first repetition is considered as an answer in the following 4 repetitions because the pressed buttons of the mouse are not clearing in time.
This might not be the answer you’re looking for, but if you know that clicks = mouse.getPressed() cleared the event buffer in your online experiment before, why not insert that line in the end routine tab?
mouse.getPressed() just checks whether a mouse button is clicked but it doesn’t clear the event buffer as far as I know. I actually added one at the beginning and at the end of the routine to check whether the button clicked is being hold until next trial, and it is.
Then I’m sorry, I can’t help you any further. I just responded to this question because you initially placed it in the builder and not in the online category.
Since you already tried psychoJS.eventManager.clearEvents();, I don’t know what else to suggest.
I’m extending my solution. My mouse is set to start at .6 seconds into the routine (before that there is a fixation cross). However, with this code, you can register clicks while the fixation cross is still being presented, therefore before the stimuli appears. No idea if this is normal or not, but it can be fix adding a time passed condition (t > .6)
Begin experiment
mouseReset=False
Each Frame
if t >= (whatever_pre_stim_tim):
if mouseReset:
clicks = mouse.getPressed()
if clicks[0] or clicks[2]:
continueRoutine = False
mouseReset=False
elif sum(mouse.getPressed()) == 0:
mouseReset=True
@wakecarter or @niclai or @LukasPsy how do you translate the solution code to JS? Does it do well with autotranslate or do we need to make some adjustments?
@aisa2, I’m using the autotranslation and it works fine. However, I had to make a custom sum function because the autotranslated sum function just doesn’t work.
Also, maybe this is just a problem with my computer because I haven’t been able to properly test it, but sometimes one of the clicks does not allow me to continue. So if I left-click the routine does not end, even if I wait some seconds. Only when I use the other click it gets captured and the routine end. However, this may be my computer because I piloted some people and no one reported this.
But then this behaviour should be consistent, right? What I have is that during most of the experiment works ust fine. But in some few trials I get this problem. Feels like the buffer of the mouse is just not cleared for some reason, and then clicking the other button a couple of times clears the buffers. This is pure guessing tho.
I don’t think the mouse has a buffer. To ensure new clicks only you could set a flag alreadyClicked in Begin Routine which = 1 if one of the buttons is already pressed. In Each Frame you set it to 0 when it equals 1 and no buttons are pressed and then only run the rest of the code when it equals 0
I have also had clicks not register while online, but there seems to be no pattern to when this happens. Usually if I click again it works. But this could be an issue for people that need precise reaction times. I think this is an issue for another thread…