Escape Key Code

Any ideas why this code to escape from the experiment would not be working?

   
if event.getKeys(['escape']):
        print("QUIT EXPERIMENT")
        core.quit()

Initially, it was but has recently stopped…
Many thanks for any suggestions!

Shouldn’t it be the following?

keys = event.getKeys()

if 'escape' in keys:
        print("QUIT EXPERIMENT")
        core.quit()

For some reason this still did not work for me…

The larger snippet of code for more context:

while instructions_still_running and instructionsTimer.getTime() > 0 - frameTolerance:
    start_time = instructionsClock.getTime()
    keys = event.getKeys()

    if start_time > 0 - frameTolerance and instructions1.status == NOT_STARTED:
        start_time = instructionsClock.getTime()
        instructions1.tStart = start_time
        runInstructions(instructions1)
        instructionEnd = instructionsClock.getTime()
        instructions1.tStop = instructions1.tStart + instructionEnd

        nextComponent = instructions1.tStop + (instructions1.tStop - instructions1.tStart)

    if nextComponent > instructionsClock.getTime() and instructions2.status == NOT_STARTED:
        start2 = instructionsClock.getTime()
        instructions2.tStart = start2
        runInstructions(instructions2)
        instructionEnd = instructionsClock.getTime()
        instructions2.tStop = instructions2.tStart + instructionEnd

        nextComponent2 = instructions2.tStop + (instructions2.tStop - instructions2.tStart)

    if nextComponent2 > instructionsClock.getTime() and instructions3.status == NOT_STARTED:
        start3 = instructionsClock.getTime()
        instructions3.tStart = start3
        runInstructions(instructions3)
        instructionEnd = instructionsClock.getTime()
        instructions3.tStop = instructions3.tStart + instructionEnd

    if 'escape' in keys:
        print("QUIT EXPERIMENT")
        core.quit()

    experiment_window.flip()

I originally had it inside of the runInstructions() function but took it out for ease.

I can’t see keys = event.getKeys() in your code.

Sorry, it is the line of code above that did not get copied in. Fixed now but still does not seem to work…

For one to go to the next instructions component, they must press space, which I have coded in the runInstructions() function.

1 Like

I can’t see any reason this wouldn’t work - you’ve essentially got the same code that a Builder experiment would use to end the experiment and those are working fine. Could you send the full experiment? It would be easier to see what’s going wrong if I could run it to test