When I call uigetdir, how can I enter a directory path using Java Robot?

7 次查看(过去 30 天)
I'm trying to use Java Robot to enter a directory path into the "Select Directory" pop-up that appears when uigetdir is called.
I've tried the following code but the robot "types" the letter h before the pop-up appears and the letter i appears after the pop-up is manually closed.
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
robot = Robot();
robot.keyPress(KeyEvent.VK_H);
robot.keyRelease(KeyEvent.VK_H);
uigetdir;
robot.keyPress(KeyEvent.VK_I);
robot.keyRelease(KeyEvent.VK_I);
What I would want is the robot to type in hi in the "Select Directory" pop-up in the "File Name" field.
I really appreciate any help you can provide.

采纳的回答

Jan
Jan 2013-3-6
It is a strange and indriect approach to let the robot remote-control the file selection dialog. If you use a TIMER to let the robot click during the UIGETDIR dialog is open, further timing problems may occur. Therefore I strongly recommend to use another approach. What do you actually want to achieve?
  1 个评论
Cinimod
Cinimod 2013-3-6
I am trying to automate testing a GUI and for this one test case, one of the first steps involves clicking on a "Load File" button. The button uses a callback that eventually opens the dialog box for selecting a directory (via the uigetdir function).
In order to select the file I can either browse to the file via this dialog box or I can type in the full file path in the dialog box's "File Name" space.
For the automated test run, I can imitate clicking on the "Load File" button by using a callback function in my test script. When I do this, the dialog box opens up, but at this point, I am unsure how to select a file via automation.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Robotics 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by