Assigning a hotkey in app designer to activate the push button
9 次查看(过去 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!