How to control multiple pushbutton with keyboard using GUIDE?
이전 댓글 표시
I've been trying to make a piano in MATLAB (without sound, thus far) using my keyboard to play the piano instead of the mouse. So far I've been able to perform the "execution" of one pushbutton, but when I try to use another one it will not execute.
% --- Executes on key press with focus on figure1 and none of its controls.
function figure1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata structure with the following fields (see FIGURE)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
switch eventdata.Key
case 'c'
uicontrol(handles.C)
C_Callback(handles.C,[],handles)
case 'd'
uicontrol(handles.D)
D_Callback(handles.D,[],handles)
end
This is how the KeyPressFcn looks like in my m.file. I haven't yet done the whole piano, only the C and D key. As I mentioned, I can press one button, and it will be "marked", but I can't do both C and D in one run.
Thanks in advance!
댓글 수: 5
Adam
2016년 8월 31일
So what happens when you try the second key?
Jahno
2016년 8월 31일
Henry Giddens
2016년 9월 5일
Is it be possible that the focus is no longer on the figure and is instead on the pushbutton associated to the previous key?
This is presumably caused by the line
uicontrol(handles.C)
Geoff Hayes
2016년 9월 5일
Henry - I think that your comment should be an answer. :)
Henry Giddens
2016년 9월 5일
Thanks Geoff, I have copied and expanded on this below. (I am new to Matlab Answers!)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Just for fun에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!