Detect program GUI using Java - java

Is there any Java code can help to detect another program GUI part by part?
For example, detect the size of the GUI, detect the location of the button.

Selenium does something similar to this but it is really not there. It will work only for browser-based apps/programs/sites. But if your target programs are browser-based, it will probably be a great tool.
For desktop programs, you might give a look to the createScreenCapture(Rectangle) method from the java.awt.Robot class to get a BufferedImage with the contents of the screen, and then it is up to you to try to make sense of the image, which would not be easy. Also, you might use the Robot to try to juggle out windows as needed, press buttons, type text, or whatever is needed to find out what you want. All of this will be a lot of work.

Related

Java Detecting when a key is pressed

I am trying to make a program that will run infinitely until I press a button. This program will run in the background so there is no display open at all times.
while(!certainButtonIsPressed)
{
//Do Something
}
How do I make it so that while certainButtonIsPressed is valid while not making a KeyBoardListener class? Is this possible without a Key listener of some sort?
Thanks!
You ask:
I am trying to make a program that will run infinitely until I press a button. This program will run in the background so there is no display open at all times. while(!certainButtonIsPressed) { //Do Something } How do I make it so that while certainButtonIsPressed is valid while not making a KeyBoardListener class? Is this possible without a Key listener of some sort?
So basically what you're trying to do is to trap all the keypresses of platform from a background process, and this is something that core Java cannot do without use of platform-specific native code that you provide, either through some library that you've obtained, or by meshing your Java program with some key-trapping utility. So if your question is, can this be done via just Core Java? And the answer is: no.
If you are looking for non-Java platform specific solutions, then you will need to give further details. My recommendation though is not to use Java for a task that can be performed much more easily and fully with another language, perhaps a scripting language such as AutoIt, if this were for a Windows environment.

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?
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:
Write your own JNA or JNI code to register your hot keys, or
Find a library that does this and call its methods, or
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.

Accessing iSight via Java on OSX

So after doing a lot of digging around here, and elsewhere, there is no good, simple, CURRENT way to grab images from iSight in Java. So first of all I would love if someone could point me to a good way to do this, and OpenCV does not work for Java in case you were thinking of that.
Here's a workaround of sorts that I'm thinking about using, even though it is incredibly flawed:
Open up Photo Booth
Use java's Robot class to grab an image of the portion of the screen that holds the feed from the iSight.
If you just need to capture single pictures, you could use a command line program like imagesnap, run it with Runtime.exec, save the picture to a temp directory, then open the image file.

Java: how to disable mouse and keyboard system wide

Alright, I am not sure if this is even possible with Java specifically, but I am working on a a small program very similar to synergy and I need to be able to completely disable input from the mouse and keyboard on the host computer, but still record the input within the program. I can not think of any clean and robust ways to do this with Java. Is this possible?
Any way you will have to use JNI for such a purpose.Have a look at this blog ,it will give you some idea.

How to handle a GUI of an external software from within Java code

I need to run an external application from within my Java code. I can run the application with Runtime r = Runtime.getRuntime() and then r.exec(...), however, this brings up the GUI of the application. And I still need enter some settings in some fields and press enter. So:
Is there some way to handle a GUI (filling out fields, pressing "return"..etc) from within Java code?
Thanks in advance for any answers,
Anas
Use the AWT Robot class:
"This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed."
Thanks RichieHindle and Vanya for your comments. AWT Robot class does work with an external softwatre (in this instance, I only need to press an enter. It did that, no problem). But further handling seems quite difficult, since every key stroke (entering a username) needs a java line (unless there is someshort cut that I missed). I will try to automata the process more, or find some work around.
Thank you, this was informative.
Anas

Categories