필터 지우기
필터 지우기

KeyPressFcn problem

조회 수: 24 (최근 30일)
Razvan
Razvan 2011년 5월 21일
답변: Norbert 2020년 10월 15일
Hi everyone,
I have a problem regarding the KeyPressFcn of a figure. I try to make a GUI in which I want to control something with the keys. If the focus is on the main figure then this is possible but after I press a button and the focus moves to the button, the KeyPressFcn doesn't activate. How can I move the focus back to the main window (to the background) after I press a button, in order to be able to record again the pressed keys?
Here is a small example in which after the button is pressed the keys are not recorded until I click with the mouse somewhere on the background and the focus moves again to the main window.
function crazy_gui
f = figure('KeyPressFcn', @(handle,event) disp(event.Key), 'Position',[500,500,500,500]);
hButton = uicontrol('Style','pushbutton','String','Crazy Button',...
'Position',[200,200,100,100],...
'Callback',@button_Callback);
function button_Callback(handle,event)
disp('Focus changed to the button! Now you cannot record the pressed keys');
end
end
Thanks,
Razvan

채택된 답변

Matt Fig
Matt Fig 2011년 5월 21일
Try the WindowKeyPressFcn instead.
  댓글 수: 2
Razvan
Razvan 2011년 5월 21일
Thanks a lot!
Razvan
Razvan 2011년 5월 21일
And how can I disable the WindowKeyPressFcn property while a slider is active, such that in that case the keys control only the slider and don't do anything else outside the slider?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Norbert
Norbert 2020년 10월 15일
Thanks a lot for your hint Matt, did not work out in my case.
in order to get the function active i always have to click on the figure.
Best
Norbert

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by