how to set controller by keyboard arrows in matlab app designer
16 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Gowtham
2023-9-12
编辑:Gowtham
2023-9-27
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!