Perform certain actions while the mouse is clicked?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to display Image A and play Sound A while the mouse is clicked. Once the mouse is unclicked I would like Image B to be displayed and Sound B to be played for 3 seconds. This will be done for mutliple trials. I am using PsychToolBox.
Right now I have a code that isn't breaking, but is just cycling through my image stimuli without playing any sound and without any influence of the mouse.
I think there may be an issue with how my loops are structured and how I am calling to the mouse click. The stimuli have been read in using other functions.
Really I think I just need some direction on where to put each of my loops and how to tell the loop to do somethig while the mouse is pressed.
Thanks for any tips, I am brand new to programming!
try
[window,rect]=Screen('OpenWindow',0);
Screen(window,'BlendFunction',GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); % tells MATLab how to read the transparency data of images
ShowCursor('Hand')
for(i = 1:length(stimuli_img))
%%% gray background aka graySquare
imData_gray = base_img(4).imData_base;
imageTexture_gray = Screen('MakeTexture', window, imData_gray);
Screen('DrawTexture', window, imageTexture_gray,[],[loc_b_x, loc_b_y, loc_b_x + imX_b, loc_b_x + imY_b]);
%%% stimuli images ---- one of the images I would like displayed while the mouse is NOT pressed
imData = stimuli_img(i).imData;
imageTexture = Screen('MakeTexture', window, imData);
Screen('DrawTexture', window, imageTexture,[],[locx, locy, locx + imX, locy + imY]);
%%% orange hexagon aka buttonOFF ---- one of the images I would like displayed while the mouse is NOT pressed
imData_hex = base_img(1).imData_base;
imageTexture_hex = Screen('MakeTexture', window, imData_hex);
Screen('DrawTexture', window, imageTexture_hex,[],[loc_h_x, loc_h_y, loc_h_x + imX_h, loc_h_y + imY_h]);
while GetMouse == 1
beepData = audioread('Beep_1.wav'); % sound file I would like to play when mouse is pressed
frequency = 48000;
sound(beepData, frequency);
%%% blue hexagon aka buttonON ---- one of the images I would like displayed while the mouse is pressed
imData_hexON = base_img(2).imData_base;
imageTexture_hexON = Screen('MakeTexture', window, imData_hexON);
Screen('DrawTexture', window, imageTexture_hexON,[],[loc_h_x, loc_h_y, loc_h_x + imX_h, loc_h_y + imY_h]);
end
Screen('Flip',window);
WaitSecs(dur)
%%% Emergency Escape
[keydown, time, keyCodes] = KbCheck; % kbcheck shows what keys are currently being pressed
key = KbName(keyCodes);
if(strcmp('esc',key) | strcmp('ESCAPE',key)| strcmp('Escape',key)) % use Escape key as an emergency escape
break
end
%%% End the Emergency Escape Code
%%%
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!