End Study Button

Hi, I’m very new to coding and I’m using PsychToolbox in Matlab 2021b.

I’m creating a study that will advance through different text screens and I have created just a disc start to it so far.

I am wondering how (and where) I can place a piece of code that will allow my participants to press the escape key at any time throughout the study to end it.

The following is the code I have so far:

ListenChar(2); 

ScreenNumbers = Screen('Screens'); 
OutScreen = max(ScreenNumbers); 

Screen('Preference', 'SkipSyncTests', 1); 

[scrn, rect] = PsychImaging('OpenWindow',SCREEN_TO_USE, [],[0 0 800 600]); 

Screen('TextSize',scrn,24); 
DrawFormattedText(scrn,['Thank you for taking part in this experiment. \n\n Please take time to read the information infront of you. \n\n Do not hesitate to ask any questions. \n\n Press any key to continue.'],'center','center',[],60)

Screen('flip', scrn); 

KbStrokeWait; %wait for any keypress
    DrawFormattedText(scrn,['You are about to be presented with a video. \n\n Please pay attention as you will be asked to recall events afterwards. \n\n When you are ready, press any key to play'], 'center', 'center');
    Screen('flip', scrn); 

KbStrokeWait;% wait for any keypress
    sca; 

ListenChar(1)