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

7 Ansichten (letzte 30 Tage)
Jenni French
Jenni French am 16 Jul. 2019
Beantwortet: Sreeram am 20 Sep. 2024
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?

Antworten (1)

Sreeram
Sreeram am 20 Sep. 2024
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.

Kategorien

Mehr zu Develop Apps Using App Designer 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!

Translated by