Effacer les filtres
Effacer les filtres

how to set controller by keyboard arrows in matlab app designer

7 vues (au cours des 30 derniers jours)
Roye Vadana
Roye Vadana le 7 Fév 2022
Modifié(e) : Gowtham le 27 Sep 2023
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

Réponses (1)

Gowtham
Gowtham le 12 Sep 2023
Modifié(e) : Gowtham le 27 Sep 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

Catégories

En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by