开发者

How to insert text to another program's textbox using java

开发者 https://www.devze.com 2023-02-07 00:07 出处:网络
How can I insert some text into a textbox of another program using java. for example, yahoo messenger chatbox.

How can I insert some text into a textbox of another program using java. for example, yahoo messenger chatbox. I'm not trying to make a yahoo bot, It's just an example of what I'm looking for.

开发者_StackOverflow社区

Thank you!


As Jonathon noted in the comment, you can try using java.awt.Robot. But you'd need to know the exact location of target text field, and have it visible on the screen.

You can have something like:

Robot robot = new Robot();
robot.mouseMove(xCoord, yCoord);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(50);
robot.keyPress(51);

Apart from that, you'd need the application to provide some native API to interact with its form, and use it via JNI.


You should use JNI (or better, JNA) and send Windows Messages to the other programs textbox. I assume the other program is not a Swing App (in which case only AWT Robot works), and by sending native windows messages you can reliable find the other programs textbox even if it doesn't has the focus or is hidden in the background.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号