Assigning a hotkey in app designer to activate the push button
8 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have a push button in app designer and I want to asign a hotkey (c) to activate it. I used this code but it does n't work. My button name is 'ResponseButtonPushed'
I separately tried
app.ResponseButtonPushed and
ResponseButtonPushed only after Case C.
Where is the issuse in my code?
% Key press function: UIFigure
function UIFigureKeyPress(app, event)
key = event.Key;
switch key
case 'c'
app.ResponseButtonPushed(app,event); %or whatever your function is. This is the name of mine]
end
2 件のコメント
Jiri Hajek
2023 年 1 月 10 日
Hi, I use the same syntax as you and never had any problem... While the app window remains in focus, this works.
回答 (1 件)
Divyanshu
2023 年 2 月 23 日
The interpretation of the description provided is that you want the button to be pushed automatically when the hotkey ‘c’ is pressed. So, proceeding with this understanding->
I have created a sample App using App-designer which has a push button and 2 additional edit fields. The button is automatically pushed when key ‘c’ is pressed on the keyboard.
The edit field ‘Key Pressed’ is for reference to see which key user has pressed on the keyboard.
The 2nd edit field gets value ‘Hello’ when the Button is pushed.
Here is the code view of the App->
methods (Access = private)
% Key press function: UIFigure
function activateBtn(app, event)
key = event.Key;
app.KeypressedEditField.Value = key;
switch key
case 'c'
app.ResponseButtonPushed();
end
end
% Button pushed function: ResponseButton_2
function ResponseButtonPushed(app, event)
app.ButtonPushedEditField.Value = 'Hello';
end
end
In R2022b you can call the call-back function ’ResponseButtonPushed’ by following the above syntax or also you can follow this syntax when calling the call-back function-> app.ResponseButtonPushed(event);
But this syntax ‘app.ResponseButtonPushed(app, event);’ throws the error ‘too many arguments.’ on both R2022b and R2019b MATLAB versions. You can retry after using any of the above-mentioned syntaxes.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop uifigure-Based Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!