| Reference | Downloads | Github

JS - Recording and Acting on Multiple Keyboard Presses

URL of experiment:

Description of the problem:
In my experiment, participants need to push the left OR right key multiple times in order to make a choice and progress to the next routine.

I have been able to achieve this in Builder pretty simply. For example, the Py Code for one trial is this:

if key_resp_14.keys == ['left', 'left']:
    continueRoutine = False
elif key_resp_14.keys == ['right', 'right', 'right']:
    continueRoutine = False

whereby pushing the left key twice or the right key 3 times will end the routine.

However I can’t figure out the JS code that would work for this. I have tried changing the syntax to JS as normal i.e.

if (key_resp_2.keys == ['left', 'left']){
    continueRoutine = false;
if (key_resp_2.keys == ['right', 'right', 'right']){
    continueRoutine = false;

but this doesn’t work. The experiment runs and I don’t get an error message. But the experiment won’t continue past the routine nor record the keys that have been pushed.
Any ideas anyone?