The moose likes Swing / AWT / SWT / JFace and the fly likes JAVA Robot Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "JAVA Robot" Watch "JAVA Robot" New topic
Author

JAVA Robot

Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 42
I simulated a game play by generating keyhits through java's Robot class.
Its like a Java program running in background that generates key presses like W A S D to accelerate, turn and brake a car.
Which key to press is controlled by some mechanism.

However my problem is that i want the Java program that simulates key press to run that game on its own. And if the game is minimized no key press simulations should be done! So that my desktop or other app running would not take any keypresses!
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1644
Add a WindowListener to your frame. When the frame is deactivated, you stop the game, when it is activated you restart the game.

There are probably better approaches than using a Robot. Maybe you can use the dispatchEvent() method to send KeyStrokes to a component. Or use a button.doClick() to click a button.

This message was edited 1 time. Last update was at by Rob Camick

Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 42
The game is not a java program...moreover i didnt create it. Its third party...without sorce code.
Its like any popular car race game like....Need For Speed....or Burnout Paradise.

How can you make such game capture AWT events....for key press etc.
 
 
subject: JAVA Robot
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com