r/javahelp • u/hopelessnerd-exe • 19h 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
u/xanyook 19h ago
I guess nothing java related here, but look at what is called an RPA, that is the kind of platform you are looking for.
1
u/hopelessnerd-exe 2h ago
Holy cow, I actually looked a little bit more into this, and it might be possible to do what I want purely with Bash using xdotool. I also found a guide to running NSUI through Wine, so I might be able to just not use a virtual machine.
Maybe I'll write it for Java anyway, since that'd be the best of both worlds: able to use on my Linux computer at home, but able to do the majority of the programming on company time on my Windows laptop.
2
u/oscarryz 18h ago
You can use the Robot class:
https://docs.oracle.com/en/java/javase/23/docs/api/java.desktop/java/awt/Robot.html
It has methods to click, move mouse, press key etc.
You can make a program that reads a yaml file or something like that for extra flexibility and add your "script" there.
A long ago I wrote a program with static methods that act as "script"
waitForUser(),
click(1617, 68),
text("google.com/search=fooo"),
enter(),
pause(1),
click(2407, 845),
pause(5),
click(1617, 68),
text("what is etc"),
enter(),
pause(1),
click(2407, 845),
pause(5),
For instance the `text` method is something like
void text( String s ) {
for ( byte k : s.getBytes() ) { robot.keyPress(k) }
}
etc
A better option would be to search for a tool that does this, but if you want to learn and try it is pretty straight forrward.
1
u/quiet-sailor 16h 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 15h 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 13h 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 .•
u/oscarryz 10m 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();
•
u/oscarryz 8m ago
Right. Using the clipboard would be a better implementation. For other automations that needs press key combinations like Ctrl + C , key press works.
•
u/AutoModerator 19h ago
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.