Reputation: 703
My program is a question/answer task:
-participant must press on space (keyboard) bar to play a sound -participant must after that press on one of the two button (mouse) -participant must press on space bar to play a sound ...
The problem is, I want to allow only one press on space bar, because user can press many time on space and play the sound x times. How to block the figure1_KeyPressFcn while waiting the mouse response, and once we have the mouse response we reactivate the function ?
function figure1_KeyPressFcn(hObject, eventdata, handles)
switch eventdata.Key
case 'space'
%% processing x task
%playing sounds 1000 ms
soundsc(y,Fs);
guidata(hObject, handles); %%// Save handles data
otherwise
disp('error');
end
end
function pushbutton1_Callback(hObject, eventdata, handles)
%processing task
guidata(hObject, handles); %%// Save the handles data
end
function pushbutton2_Callback(hObject, eventdata, handles)
%processing task
guidata(hObject, handles); %%// Save the handles data
end
Upvotes: 0
Views: 104
Reputation: 4549
You could use a global flag, something like this:
global clicked;
clicked = true;
Then, on your figure1_KeyPressFcn
function, you only call the switch
if the user has clicked, like this:
global clicked;
if clicked
switch eventdata.Key
case 'space'
clicked = false;
%% processing x task
...
end
end
And on both your pushbutton?_Callback
's, you add this:
global clicked;
clicked = true;
To set clicked
to true
and allow figure1_KeyPressFcn
to process space keys again.
Upvotes: 2