Assigning a hotkey in app designer to activate the push button
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jiri Hajek
am 10 Jan. 2023
Hi, I use the same syntax as you and never had any problem... While the app window remains in focus, this works.
Antworten (1)
Divyanshu
am 23 Feb. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Develop uifigure-Based Apps 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!