Reputation: 703
I am trying to create a program that behaves as follows:
1-press space
2-"disable" the KeyPressFcn function
3-play sound
4-make a mouse action
5-a sound will be played
6-"enable" again the KeyPressFcn function
7-return to 1
function figure1_KeyPressFcn(hObject, eventdata, handles)
switch eventdata.Key
case 'space'
set(hObject, 'KeyPressFcn', [])
soundsc(y,Fs);
otherwise
disp('error');
end
end
function pushbutton1_Callback(hObject, eventdata, handles)
soundsc(y,Fs);
set(hObject, 'KeyPressFcn', {@figure1_KeyPressFcn, handles})
guidata(hObject, handles);
end
The step 6 does not work, so the question is, how do I set hObject for KeyPressFcn from a mousecallback ?
Upvotes: 0
Views: 180
Reputation: 2409
So, some background it in order. hObject not a property you set. It's actually the handle to the object that called the function in which it in being used. So, when you use it inpushbutton1_Callback, you're actually setting the KeyPressFunction for pushbutton1! That's why it works exactly once. Instead, try this:
set(handles.figure1, 'KeyPressFcn', {@figure1_KeyPressFcn, handles})
Upvotes: 1