psychopy.org | Reference | Downloads | Github

End routine after TWO key presses


#1

Hi,

My task involves entering a percentage 0-99. I want the 2nd digit press to end the routine as its a long task, and this will speed it up for participants

Is this possible - in the GUI? I’m not a confident coder.

Thanks!
JG


#2

It would need a code component and the output would be in list format (so rather than 99 you’d get [9,9])

If mouse input would be acceptable - you could use a rating scale with a range of 0-99


#3

Many thanks for your quick reply, Oli. The first is preferably as there are versions of the task published which used the digit entry method - so this is preferable.

If you could be so kind as to explain how it is done, and where to insert code, that would be much appreciated. If code is changed, is this reflected in the builder; and similarly, do I still run it from the builder or do i have to run from the code window after adding this?

Many thanks indeed,
JG


#4

Adapted from Michaels code in a previous thread. Check out code components in the documentation. Add the following to the Every Frame tab. You won’t need a Keyboard component from what I understand.
BW

Oli

keys = event.getKeys()

if keys: # if at least one key exists in the list,
    if 'escape' in keys: # now need to check for the quit key ourselves
        core.quit() 

     elif len(keys) == 2: #if two keys have been pressed
        thisExp.addData('keys', ''.join(keys) # store keys
        thisExp.addData('RT', t) #reaction time because why not
        contineRoutine = False #end routine.


#5

Hi @Oli,

I’m not sure how well this would work in this case: when checking event.getKeys() on every frame, I think it would be pretty unlikely to actually get two keys returned. i.e. the second would need to have been pressed within a few milliseconds of the first to get collected in the in the same call to event.getKeys() . More likely, you’ll detect the keys individually as they come in (each call to getKeys() clears the buffer of previous keypresses).

That would mean storing key presses and taking action once the second has been received


#6

Thanks again Michael - I’m being too hasty and not testing this stuff!

#beginRoutine Tab
thisResp = [] #make an empty list

#every Frame
keys = event.getKeys()

if keys: # if at least one key exists in the list,
    if 'escape' in keys: # now need to check for the quit key ourselves
        core.quit() 

     else: #add this frame keys to response list
        thisResp.append(keys)
        if len(thisResp) == 2:
					thisExp.addData('response',''.join(thisResp))
        	thisExp.addData('RT',t)
          contineRoutine = False #end routine.