Zaw
Zaw

Reputation: 27

Controlling mouse when Java window is out of focus

I'm interested in writing a program that will assist me in marking exam papers online. I would like to use the keyboard to control the mouse eg if I press '1' then the mouse will be sent to a specified location and click there. This will double my work output at least. The problem is marking is done through Internet Explorer so the Java program will be out of focus. From searching this site I found that someone has written a library that can receive keyboard input out of focus but I couldn't find any such thing for mice (I don't think Java Robot works out of focus).

Does anyone know whether such a program is possible in Java using standard libraries?

Upvotes: 1

Views: 394

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

The problem of course is capturing key presses when Java is not in focus. You have three main options as far as I can tell:

  1. Write your own JNA or JNI code to register your hot keys, or
  2. Find a library that does this and call its methods, or
  3. Use a scripting program like AutoIt (if this is Windows) that is linked to your Java program, such as with sockets linking the standard inputs and outputs of both programs.

I have used the 3rd option successfully, but in fact for me, it was usually easier just to do everything in AutoIt.


Note that this statement is not true:

(I don't think Java Robot works out of focus).

The Java Robot doesn't require that a GUI has focus, and in fact does not require that a GUI be running at all.

Upvotes: 1

Related Questions