How to make buttuns react to enter/return ?

6 Ansichten (letzte 30 Tage)
Petr
Petr am 6 Nov. 2012
Hi,
I am starting to be slightly irritated by buttons...I can I make a button to react to enter/retun key when I press it when I tab on it ?? I can't find a good functioning solution anywhere. Why for example a questdlg have that function and ordinary buttons dont ??
Please help :)
Thanks, Peter

Akzeptierte Antwort

Petr
Petr am 7 Nov. 2012
Solution was simple and enough elegant for me...
.
function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
key = get(gcf,'CurrentKey');
if(strcmp (key , 'return'))
pushbutton1_Callback(hObject, eventdata, handles)
end
function pushbutton1_Callback(hObject, eventdata, handles)
%code to be executed

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 7 Nov. 2012
Define KeyPressFcn for the uicontrol.

Jan
Jan am 7 Nov. 2012
Usually the keyboard events are caught by the figure, not by the uicontrol. The later works only, when the corresponding uicontrol is active, while the figure's "WindowKeyPressFcn" catchs keys when the figure or one of its children is active.
Perhaps in questdlg another feature could be active: Hitting Tab moves the focus to the next uicontrol, and hitting Enter (or space? I cannot test it currently) will activate it. This feature is controlled by the operating system and should work on all GUIs.

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by