Pushbutton activated by Enter(return) key
5 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I would like to ask you why doesn't work when I call funtion pushbutton1_Callback inside pushbutton1_KeyPressFcn. I have besidde other things buttons where I want them to react to Enter key when user Tabs to it (+ ofcourse when user just click at it). I thought that the simplest way would be to call pushbutton1_Callback in pushbutton1_KeyPressFcn,but obviously not...how caan I do this feature ?
Thanks, Peter
5 件のコメント
Sean de Wolski
2012 年 11 月 1 日
How are you running this GUI? Are you just double-clicking on the figure? You need to run the *.m file associated with the figure:
>>myGUI
採用された回答
Petr
2012 年 11 月 7 日
1 件のコメント
Luis Santiago Hernández Castillo
2022 年 8 月 24 日
Maybe this one could be a good option too:
%bhok is the handles of your pushbutton.
%xxx represents any data for ur code.
bhok.Callback=@(src,~)okcbd(src,xxx);
bhok.KeyPressFcn=@(src,event)bhokcall(src,event,xxx);
function bhokcall(src,event,xxx)
if event.Key=='return' %#ok<BDSCA>
okcbd(src,xxx)
end
end
function okcbd(src,xxx)
%code to be executed
end
その他の回答 (2 件)
Sean de Wolski
2012 年 10 月 31 日
You can do this, you just need to feed it the correct inputs. You could probably find these by looking in the property inspector in GUIDE at the callback to see what GUIDE is feeding it.
Image Analyst
2012 年 11 月 1 日
Just put the inside of the click callback into its own function, like Button1Pressed() or something like that.
function handles=Button1Pressed(handles)
% whatever it does....
Then have the click and keypress callbacks both call Button1Pressed(). You don't need to pass in anything other than handles.
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!