フィルターのクリア

How to capture keyboard input in getrect

2 ビュー (過去 30 日間)
Ping
Ping 2011 年 7 月 12 日
Hello, all I wrote small GUI demo which has a "LoadImage" button, and in the LoadImageBtn_Callback call the LoadImage function to load image, getrect, then do some image processing and it works fine.
function LoadImageBtn_Callback(hObject, eventdata, handles)
LoadImage(hObject, eventdata, handles);
function LoadImage(hObject, eventdata, handles)
I = imread('cameraman.tif');
imshow(I);
rct = getrect;
%do image processing...
Now I want to add keyboard shortcut, and I add a WindowKeyPressFcn function of the figure, in which call LoadImage function.
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
switch eventdata.Key
case 'l'
LoadImage(hObject, eventdata, handles);
end
Now the problem is: when I click the "LoadImage" button and in the processing of getrect, if I click keyboard, all the keyboard event is missing(which is desired). But when I click the "L" shortcut to call the LoadImage function, if I click keyboard in the processing of getrect, it will appear in the matlab command window which is very annoying because I have to switch back to the GUI window. So I wonder what's the difference? And how to capture such keyboard input in the processing of getrect?
I have added breakpoint in the function figure1_WindowKeyPressFcn, but it seems that in the processing of getrect the function figure1_WindowKeyPressFcn is never called.

採用された回答

Ping
Ping 2011 年 7 月 13 日
At last I know the difference: when I click the button, the keyboard event at the time of getrect is sent to the button's event loop, not the figure's WindowKeyPressFcn. So to filter the annoying keyboard input when use hotkey, just call
uicontrol(hButton)
to give the focus to some button. Maybe a bug of WindowKeyPressFcn?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by