Azzera filtri
Azzera filtri

how to set controller by keyboard arrows in matlab app designer

7 visualizzazioni (ultimi 30 giorni)
I have a problem to set controller by keyboard arrows in matlab app designer. I cant reset my key value when there is no key Pressed. I want to make action only while some key is pressing and stop the action when the key is un pressing
function ControllerUIFigureKeyPress(app, event)
key = event.Key;
switch key
case 'leftarrow'
app.left_icon.Position = [210 98 71 102];
case 'uparrow'
app.up_icon.Position = [285 150 71 102];
case 'rightarrow'
app.right_icon.Position = [360 98 71 102];
case 'downarrow'
app.down_icon.Position = [285 40 71 102];
otherwise
app.down_icon.Position = [285 60 71 102];
app.up_icon.Position = [285 133 71 102];
app.right_icon.Position = [343 98 71 102];
app.left_icon.Position = [225 98 71 102];
end

Risposte (1)

Gowtham
Gowtham il 12 Set 2023
Modificato: Gowtham il 27 Set 2023
Hello Roye Vadana,
I understand that you want to change the position of arrow icons using keyboard arrows in app designer. To reset the position of the keys, we can use the Key Release callback which is similar to the Key Press callback you have created.
For a sample demonstration of this process, kindly refer to the updated code snippet:
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.down_icon.Position = [285 60 71 102];
app.up_icon.Position = [285 133 71 102];
app.right_icon.Position = [343 98 71 102];
app.left_icon.Position = [225 98 71 102];
end
% Key press function: UIFigure
function UIFigureKeyPress(app, event)
key = event.Key;
switch key
case 'leftarrow'
app.left_icon.Position = [210 98 71 102];
case 'uparrow'
app.up_icon.Position = [285 150 71 102];
case 'rightarrow'
app.right_icon.Position = [360 98 71 102];
case 'downarrow'
app.down_icon.Position = [285 40 71 102];
otherwise
app.down_icon.Position = [285 60 71 102];
app.up_icon.Position = [285 133 71 102];
app.right_icon.Position = [343 98 71 102];
app.left_icon.Position = [225 98 71 102];
end
end
% Key release function: UIFigure
function UIFigureKeyRelease(app, event)
key = event.Key;
% reset positions
switch key
case 'leftarrow'
app.left_icon.Position = [225 98 71 102];
case 'uparrow'
app.up_icon.Position = [285 133 71 102];
case 'rightarrow'
app.right_icon.Position = [343 98 71 102];
case 'downarrow'
app.down_icon.Position = [285 60 71 102];
end
end
end
Kindly refer to the following documentation for further understanding on callbacks in app designer https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html
Hope this helps in resolving the issue you were facing.
Regards,
Gowtham

Categorie

Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by