joe90
joe90

Reputation: 538

Best method for a Java app to access a windows process, and send commands

Basically I am attempting to control a win32 app (press a button, add stuff to a text field) etc from a java app.

Whats the best method of attempting this (i.e are there any toolkits, DDE?) or will I have to attempt to do some sort of FindWindowEx, then send a WM_LBUTTONDOWN or something?

Cheers

Upvotes: 1

Views: 1699

Answers (2)

REA_ANDREW
REA_ANDREW

Reputation: 10764

It seems that this is encapsulated inside the jna project from java.net projects:

https://github.com/twall/jna

Well it is one possibility anyway.

In one example it shows a few imports which look like they may be of use to you:

import com.sun.jna.examples.win32.GDI32;
import com.sun.jna.examples.win32.User32;
import com.sun.jna.examples.win32.GDI32.BITMAPINFO;
import com.sun.jna.examples.win32.User32.BLENDFUNCTION;
import com.sun.jna.examples.win32.User32.POINT;
import com.sun.jna.examples.win32.User32.SIZE;
import com.sun.jna.examples.win32.W32API.HANDLE;
import com.sun.jna.examples.win32.W32API.HBITMAP;
import com.sun.jna.examples.win32.W32API.HDC;
import com.sun.jna.examples.win32.W32API.HRGN;
import com.sun.jna.examples.win32.W32API.HWND;

Upvotes: 1

DMKing
DMKing

Reputation: 1715

Use the Java Robot. Class is java.awt.robot. It works great for controlling other applications. See here:

http://java.sun.com/javase/6/docs/api/java/awt/Robot.html

I actually used this to automate logins to World of Warcraft back when I played a lot. The server I played on almost always had a login queue that took about 30 minutes to get through. So I had the Windows scheduler kick off my Robot program about 4:45pm. It would send a shortcut combination to Windows to launch WoW. Then it would pause for a time then send keystrokes to enter my password and log me in. By the time I got home from work I would be ready to play without having to wait in the queue.

Upvotes: 1

Related Questions