A set of mouse/keyboard actions Java program - java

I want to build a program that does the following:
User clicks on a button (like on a GUI) to record his/hers movements.
Then, the user does a set of actions on the computer - this could be clicking on file explorer and deleting/creating/renaming a file, opening Chrome or another program etc... basically a few keyboard/mouse movements.
Then the user can specify a time at which the program should replicate this recording of movements. (The program hasn't been stopped and it uses the current time of the computer's clock to know when to do it)
Can I do something like this in Java? Searched quite a bit and couldn't see something relevant. The only thing that came to my mind since I am still a beginner is MouseEvents etc but I don't think these can be done outside the frames of GUI.
Thanks in advance I am keen to build this project!

JNativeHook is worth looking into for this and similar purposes. I found it helpful.
https://github.com/kwhat/jnativehook

Related

How can I listen for clipboard pastes not targeted at my application?

I'm developing an application which calculates and displays information which then needs to be copy and pasted into a proprietary program. To make this easier for the user, I'd like to enable them to ctl+v, move cursor, ctl+v, etc., and have my program pick up on the pastes and update the Clipboard automatically after every paste.
Is there any straightforward way of doing this? The only things I've found involve accessing DLLs and the like, and this isn't a project I can spend too much time on at the moment.
It's possible, check this project out: https://code.google.com/p/jnativehook/
That will allow you to listen to key events even when your app doesn't have focus. It won't work if they don't paste with a keyboard shortcut, though.

Quitting Java program renders Mac OS X window switching non-functional

On the Mac where I do my programming, I have an app installed called BetterTouchTool that allows me to bind keyboard shortcuts to 'gestures' on my trackpad. I have bound a gesture (that doesn't have an Apple default) to the shortcut command+Q, which quits the active program. I have found this very convenient for quickly quitting programs that I am testing, so that I can get back to writing code.
However for the graphical game that I am programming, this action makes it so that I can't use a three finger swipe to switch between windows (several other gestures are also disabled). This will also happen if I go up to the menu and click quit or if I click the red x close button. The fix is to either restart my computer or (and this is really weird) to click the in-game close button which calls System.exit(0);. I know that most players will be using this but I still want to figure out why this is happening. In addition games like Minecraft on my computer don't do this.
I am using a JFrame with setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); in the code. In an attempt to fix the issue I have tried registering a com.apple.eawt.QuitHandler that calls System.exit(0); in the handler.
I have no idea what would be considered relevant code here, so whatever you would like to see, just let me know.
I figured it out. There was one rouge Thread.sleep() call in my JFrame that was somehow effecting my system.

Start A Program On A Certain Screen

I'm making a program which for myself personally, would be very useful and remove one of the many things that annoy me. :p To sum it up, I'm making a java application to register a global keyboard+mousemotion listener, and when a certain key on the keyboard is pushed it opens a program. What my java program would do, is before it goes directly to the program to open it, the java program will intercept the call and say 'open on the screen that contains the cursor'. And then will continue to launch the program, but make it open on screen 1,2,3,4 etc.
What my question is, how can I make for example google chrome open on screen 1,2,3,4 etc. Is it possible with java?
Thanks
You can use the java Runtime class. Here is an example Maybe you can tell your operating system which screen you want via terminal. (In linux DISPLAY env variable.)

Want to create mouse clicks on a window with java

I want to create java code which will stimulate a mouse click on any window of a windows OS application - eg browser, word etc.
Can someone suggest how I can begin ? I don't know which API's are needed for this.
I also need to know if this is a very complex task and will require more than just
core concepts of Java.
Thanks in advance.
The class you would want to use for this task is the Robot class: http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
It may require more knowledge than the core concepts (depending on what you consider core), but Java is a good language to deal with this kind of thing.
Depending on what you seek to do with this knowledge, this may end up a very complex task. For example, if you sought to click on a specific button on the screen, you would need some way to analyze the screen (a very hard task). If you know where every button is already, you just move to the x, y location and cause a click to occur.

Recommended technology choice for desktop application

I am creating an application that is essentially a financial alerts site. I am a basic level Java programmer, and I have created some of the logic for alerts in Java.
I want to be able to have pop-ups appear on the desktop whenever something "interesting" happens (interesting depends on %change, liquidity and a few other simple factors).
What is the best combo of technology to implement something like this?
I would use the java.awt.SystemTray in Java SE 6. It's cross-platform and pretty easy to use.
Although some people hate the balloon notifications in Windows, they're the least obtrusive popups, since they can be ignored by the user or easily dismissed. Most importantly, they can't be missed by the user who has been away from the computer, because balloons (at least in Windows XP/Vista) use system idle timers to determine when's the right time to disappear.
Some prefer more traditional toast notifications, similar to those shown by Outlook - they show up and slowly fade out, giving the user some time to interact with them if needed.
I had the same problem and finally solved it using an undecorated, alwaysOnTop window.
And thanks to this blog entry I found the TimingFramework, and now it even is translucent, fades in and out, goes 100% opaque on mouse over etc. In conjunction with the SystemTray and TrayIcon the behavior is nearly as that of Outlook.
Oh, I have to note, that other than the second link, I do the fading out with
AWTUtilities.setWindowOpacity(window, op);
You could write a java program that resides in the system tray, but I am not sure if there are cross platform compatible ways to do this. maybe you have to use a platform specific library for Win, Mac, Linux, ...
I'd just create a message window and animate it. Then add SystemTray support and voila, you're done.
In Delphi you can do that pretty quickly, but you can't easily reuse your java logic
You can just run you program in "silent" mode, without creating any windows by default, maybe just a little icon in the taskbar which when double-clicked will open a settings window. The program will be running in the background and creating windows with the set focus whenever an event happens.
But in my opinion, a slide window or at least a balloon tooltip is a better idea.

Categories