nedroid
nedroid

Reputation: 193

How to access and control other window ..java?

I like to do a program which can control other program(window). I would like that my program automatically click button and get others states. But for now i am just asking how to access to this other program/process with java.

Upvotes: 1

Views: 1359

Answers (2)

cjds
cjds

Reputation: 8426

Try java.awt.Robot

How to press keys

import java.awt.Robot;
import java.awt.event.KeyEvent;

Robot robot = new Robot();

static int keyInput[] = { KeyEvent.VK_SPACE };
robot.keyPress(keyInput[i]);

How to manipulate mouse

import java.awt.event.InputEvent;

robot.mouseMove(300, 550);//MOVING MOUSE
r.mousePress(InputEvent.BUTTON1_MASK); // CLICKING MOUSE

InputEvent.BUTTON1_MASK = left button

InputEvent.BUTTON2_MASK = middle button

InputEvent.BUTTON3_MASK = right button

Here's a good tutorial to start

Upvotes: 5

OmniOwl
OmniOwl

Reputation: 5709

Try have look at the Java Robot Class.

Upvotes: 2

Related Questions