• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAVA Robot  RSS feed

 
Ashish Malik
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashish Malik
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!