tags:

views:

27

answers:

1

I'm learning about AI and (just for fun and practice, not profit or anything evil) I'd like to write a little bot to play a rinky-dink Flash game for me.

As a Microsoft hater, I'm embarrassed to say that I know and have used the required function calls some time ago under Windows, programming in Delphi. But these days I try to do everything under Linux and I don't seem to have any idea.

Requirements:

  • to grab part of the screen's contents in image or bitmap form, periodically or on programmatic request;
  • to simulate mouse pointer moves and left clicks under programmatic control;
  • keyboard grabbing might come in handy too.

Ideally, I'd like to do this from a Clojure application running in the JVM, so a Java compatible library would be the cat's meow. But failing that, I could write myself a C program to mediate between X Window and my app via local TCP/IP.

+3  A: 

You can always rely upon the good old java.awt.Robot class, which, i think, has all the features you're asking :

  • moving mouse
  • capturing a Rectangle on screen
  • clicking mouse
Riduidel
Oh wow, I used to think that class was only suitable for testing Java programs. But the javadoc can be interpreted to mean it will work with any program. I'll have a look and report back, thanks!
Carl Smotricz
It works for any program. The greatest (in the sense the most fashionable of that term) use of Robot is that applciation generating mouse track for day-long time periods : http://www.flickr.com/photos/anatoliy_zenkov/sets/72157623274370724/
Riduidel
And right you are. With just 17 lines of code, my program grabs a screenshot and can find and press the "start" button. The rest might be a little more work, but thanks to you I'm well on my way.
Carl Smotricz