Key for Interrupt and Quit

371 views
Skip to first unread message

Samuel Corbin

unread,
Nov 18, 2013, 7:31:15 AM11/18/13
to psychop...@googlegroups.com
(I'm working in Coder view, I have no idea how Builder works.)

This is likely a simple/stupid question, but I cannot for the life of me figure out how to make a key that quits the experiment (aside from adding hundreds of 
if event.getKeys():
- one for every single step in the experiment).

I want a key I can press to abort the experiment in case something goes wrong and I need to stop/restart it.

I'm also not entirely sure what function(s) to use to close the program before it's done (it's running a pyglet window called "window"). I haven't had to confront this previously since everything exits nicely at the end of the experiment without any need for explicit instructions.

Jeremy Gray

unread,
Nov 18, 2013, 10:36:21 AM11/18/13
to psychop...@googlegroups.com
I think you pretty much need to check whenever you might need to escape out. Typically you don't need hundreds of checks--often once at the inner-most (fastest cycling) part of a loop, and anytime you are waiting for the user to "click ok to continue". you just need to be able to break out, not to be able to do so within milliseconds in all circumstances. so 100ms delay (or a whole second) would be fine from a user-interface standpoint, and easy enough to code.

Its possible that a separate thread might be able to check for a special key (like 'escape') in the background, but you'd need to code this yourself.

I recommend this syntax:
    if event.getKeys(['escape']):

so that only 'escape' is removed from the key list (thereby not interfering with other possible key checking you might want to do).


--Jeremy


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/8bf87fa3-5311-4130-a67f-342a1f58b078%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jeremy Gray

unread,
Nov 18, 2013, 10:40:27 AM11/18/13
to psychop...@googlegroups.com
ps. calling core.quit() should close things down nicely:
    if event.getKeys(['escape']):
        win.close()  # assumes your visual Window is named win; seems optional
        core.quit()

--Jeremy

tomasz....@gmail.com

unread,
Jan 10, 2014, 7:58:21 AM1/10/14
to psychop...@googlegroups.com
Hi,
how to add e.g. c for continue, please?

regards,
t.

Jeremy Gray

unread,
Jan 10, 2014, 8:27:55 AM1/10/14
to psychop...@googlegroups.com
Can you elaborate what you want to happen?

It sounds like you want pressing 'escape' to mean "suspend but don't
quit the program". Instead show a dialog where 'c' will go back to
running the program as if nothing had happened (un-suspend), otherwise
quit the program via core.quit()?

--Jeremy
> https://groups.google.com/d/msgid/psychopy-users/02c67f18-b42f-4b0f-899d-49281892f5d3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages