How can I use the enter key to change focus in App Designer?

6 ビュー (過去 30 日間)
Jenni French
Jenni French 2019 年 7 月 16 日
回答済み: Sreeram 2024 年 9 月 20 日
I am creating an app in App Designer with several input fields for variables and want the enter key to be synonymous with the tab key. That is that pressing enter on the keyboard will move the focus to the next input field as tab does. I was going to use uicontrol, but this isn't supported in App Designer. Are there any workarounds?

回答 (1 件)

Sreeram
Sreeram 2024 年 9 月 20 日
Hi Jenni,
1. If you are using MATLAB prior to R2022a, there is no function to programmatically focus a UI component. However, you may work around it by sending automatic “tab” key press whenever a “return” key is encountered. To achieve this, add a "WindowKeyPressFcn" to the app's "UIFigure" and include the following code:
if strcmp(event.Key, "return")
import java.awt.*;
import java.awt.event.*;
rob = Robot;
rob.keyPress(KeyEvent.VK_TAB)
rob.keyRelease(KeyEvent.VK_TAB)
end
You may refer to the below MATLAB Answers thread for more details:
2. If you are using MATLAB R2022a or later, you can use “focus” function to programmatically focus a UI component. You may tweak the solution given in the below thread by replacing “tab” with “return” appropriately:
I hope this helps.

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by