%% the most critical part of the code
clear_Screen = Screen('MakeTexture', window, const.img{curr_img_type, curr_img_index});
                Screen('DrawTexture', window, clear_Screen, [], [const.winWid/2-300, const.winHeig/2-300, const.winWid/2+300, const.winHeig/2+300]);
                Screen('Flip', window); % draw stimulus pic and onset
                tms_lock = 0;
                
                tic %start timing
%% pic presentation time(160ms/310ms); TMS pulse start time(150ms/300ms)
                while toc<const.img_show_time(curr_show_time_index) %before pic presentation time
                    if abs(toc-const.img_show_time(curr_show_time_index)+0.01)<0.001 && ~tms_lock % tms pulse be applied 10ms before the pic disappears
                        tms_lock = 1;
                        Screen('Flip', window);
                        start(tms_timer); % start tms pulse
                    end
                    [KeyIsDown, ~, KeyCode] = KbCheck;
                    if KeyIsDown 
                        flag=1; break;
                    end    
                end
                if flag==1; break; end
