Welcome! Log In Create A New Profile

Advanced

Escape hotkey

Posted by gneblett 
Escape hotkey
February 18, 2026 08:02PM
Dear Jaewon,

I have built a task that requires an animal to fixate while a sine grating travels across the screen. I added the x hotkey to manually exit the task at any time. When we press this x, the task does not immediately quit. It seems to want to cycle through all instances of reward, or sometimes it will not even activate the escape at all. I have attached my timing file and userloop. Any advice would be greately appreciate. Thank you!
Attachments:
open | download - Gin_RF.m (71.3 KB)
open | download - Gin_RF_userloop.m (165 bytes)
open | download - Gin_RF.txt (17 bytes)
Re: Escape hotkey
February 18, 2026 09:38PM
If you are using the hotkey definition shown in the below link, it aborts only one eyejoytrack() or one run_scene() as explained there.
https://monkeylogic.nimh.nih.gov/board/read.php?2,202,202#msg-202

If your eyejoytrack() or run_scene() is placed in a loop, the command is stopped by the hotkey but the task is not, because the loop is still running. You need to handle the loop on your own way. For example,

<code>
abort_task = false;
hotkey('x', 'abort_task = true; escape_screen(); assignin(''caller'',''continue_'',false);'); % hotkey to set abort_task
.
.
.
while true
if abort_task, break, end % escape the loop when the hotkey is pressed
.
.
.
end % end of the while loop
</code>

----------

I also see you create many SineGratings individually. You can create multiple graphics with one adapter by using the List property.
https://monkeylogic.nimh.nih.gov/docs_RuntimeFunctions.html#SineGrating
https://monkeylogic.nimh.nih.gov/docs_ScriptingScenes.html#GraphicAdapters

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.