Sorin Trimbitas
Sorin Trimbitas

Reputation: 1497

Java - Robot keyPress issue

I'm trying to send keystrokes (like a virtual keyboard) from my Java code, but I encounter some issues. It works perfectly on normal applications (for example, Notepad, browsers etc.), but not on games (fullscreen or windowed mode).

This is the stripped code I'm using:

import java.awt.Robot;
import java.awt.AWTException;
import java.awt.event.InputEvent;

Robot robot;

robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);

How can this problem be fixed?

Upvotes: 0

Views: 3084

Answers (3)

nukebauer
nukebauer

Reputation: 331

I just had the same problem myself, the problem for me was that the game was running under admin privileges, and my programm wasn't. If i launched it via console with admin rights it worked.

Upvotes: 1

user793623
user793623

Reputation:

I'm sure you already got it working...

Robot robot = new Robot();

Upvotes: 1

Alpine
Alpine

Reputation: 3858

Refer to "Full screen mode robot keypresses simulation".

Upvotes: 0

Related Questions