End Routine After Key-release/inactivity

Hi all,

I have been working on the same project for the better part of a year. A lot of you helped me and for that, I thank you and hope to enlist your help once more!

I currently have a routine set up that does the following:

  • Screen initialized with a rectangle of 10px x 100px

  • When you hold down space, the rectangle grows by a rate of: 10*(t*5)

I would like to be able to stop the routine once the key is lifted.

I have tried to implement some of the different solutions on this forum but I believe that one of the lines in my growth argument might be causing issue:


for theseKeys in keys:
    # The duration == None disables my ability to use duration
    # as a metric, but I need it to have continuous growth!
    if theseKeys == 'space' and theseKeys.duration==None:
       sq.width = 10*(t*5)
       keyrt = trialClock.getTime()

if keyrt is not None and keyrt > 2:
    core.wait(.5)
    continueRoutine = False

I have a text component that displays the rt on the screen, I have it set to 2 as an arbitrary amount but would ideally like to do something like:

if theseKeys.duration >=2: continueRoutine = False

But no such duration is stored!

Any help would be greatly appreciated!

Edit:

It works now!

For anyone interested:

// Begin Routine
sq_key.keys = undefined;
sq_key.rt = undefined;
sq_key.duration = undefined;
sq_key_allKeys = [];
sq.width = 10;

sq_key.clock.reset();
sq_key.start();
sq_key.clearEvents();

//Each Frame
let theseKeys = sq_key.getKeys({keyList: ['space', 'right'], waitRelease: false, clear: false});
sq_key_allKeys = sq_key_allKeys.concat(theseKeys);

if (sq_key_allKeys.length > 0) {
    sq_key.keys = sq_key_allKeys[sq_key_allKeys.length - 1].name;
    sq_key.duration = sq_key_allKeys[sq_key_allKeys.length - 1].duration;
    sq.width = (10 * (t * 5));
    console.log(sq.width);
    console.log(sq_key.duration);
}

if (sq_key.duration > 0) {
    console.log(sq_key.keys);
    psychoJS.experiment.addData('Square_Size', sq.width);
    continueRoutine = false;
}
1 Like

Thanks for sharing your solution @DavidBrocker!