How to capture keyboard input in getrect

3 vues (au cours des 30 derniers jours)
Ping
Ping le 12 Juil 2011
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.

Réponse acceptée

Ping
Ping le 13 Juil 2011
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?

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by