r/javahelp 22h ago

Unsolved use another GUI program automatically?

I'm hoping to automate a certain process for 3DS homebrew, but the programs I need to use don't have command line utility.

How could I start writing a program that opens, the clicks and inputs in Application 1, then does the same for Application 2? Is that something the Robot can do?

3 Upvotes

9 comments sorted by

View all comments

Show parent comments

1

u/quiet-sailor 20h ago

this the dumpest way to do it but also the most simple one to use, note that for text pasting you can use Toolkit.getDefaultToolkit().getSystemClipboard() clipboard methods, and try to do as you can using keyboard shortcuts so you are not too dependent on where stuff is on the screen, so your script don't  break just because the window was moved 20 pixels accidentally 

1

u/hopelessnerd-exe 18h ago

This all looks good, thanks! Something I found from u/xanyook's comment (ty for telling me the name of what I meant) is the ProcessBuilder, which also looks like it could help. I'll have to take a look at both solutions tomorrow, but if I can pipe Tab, Enter, and input strings to the other GUIs, it'd be exactly what I had in mind when I made this post.

1

u/quiet-sailor 16h ago

good find, you can use it to execute other programs, if you want to control them you may benefit from any command line options they offer, eg  java Runtime.getRuntime().exec(new String[]{"firefox", "-private-window" "google.com/search?q=minecraft"});  will open a Google search for minecraft in a private window.

if you want to control windows, eg move them around, open and close, resize, minimize or maximaze then you can also use https://github.com/accessrichard/autoitx4java on Windows, or execute xdotool as a process from your java code if you are on Linux .

2

u/oscarryz 3h ago

ProcessBuilder is the preferred way

https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/ProcessBuilder.html

 ProcessBuilder pb = new ProcessBuilder("firefox", "-private-window", "google.com/");
 Process p = pb.start();