Monday, May 19, 2008

java.awt.Robot and the Facebook's Word Challenge Bot

Imagine that you have a Java GUI program written using the AWT and Swing libraries, and you'd like to automate the program. For example, you'd like to automatically supply GUI input events from the keyboard and mouse to the program. In this way, the program could operate without user intervention. This type of automation might be useful for testing purposes, or to produce a self-running demo program.

java.awt.Robot is a new class in JDK 1.3, designed to handle this type of automation. It's a way to automatically feed input events to a program. The events are generated in the native input queue of the platform, as if they had actually been generated by the user. For example, using java.awt.Robot, you can generate an event that is equivalent to a user moving the mouse to particular (X,Y) coordinates on the screen.

You can see an example on how to use this class on this link.

Facebook's Word Challenge Bot

Now lets see how can we use this in making our cool bot for the Facebook's word challenge game.

In this game you are required to construct words whose lengths range from 3 to 6. No need for a dictionary to do that, the range is already small enough to try all combinations of letters in a reasonable amount of time, then use the java.awt.Robot to print this output on the keyboard while you keep the focus on the game, you'll find it so much fun :)

Here's a link to the Netbeans project I used to make the bot.

And here's the bot itself.

Usage

  • Start the game and Know the allowed alphabet.
  • Edit the batch file provided with the game.
  • Add the alphabet at the end as the first command line arguments all in a single string.
  • e.g. If the allowed alphabet was {a, b, c, d, e and f} add "abcdef" - without the quotes - at the end of the file.
  • After adding the alphabet add an integer from 3 to 6 indicating the maximum length you desire for the letters generation.
  • e.g. Adding 4 to the end of the file generates words of lengths 3 and 4.
  • Now save and close.
  • Run the batch file.
  • Set the focus at the game (Just click at any place in the game's window).
  • Watch your score :)
Of coarse the program is subject to many modifications, you are encouraged to do your modifications and send me the updates if you want.

Enjoy,

12 comments:

Anonymous said...

enta fata a7lamy :d eh el gamal da

Amr Kabardy said...

CoOol.. Nice post, with valuable info, and cool bot :)

Unknown said...

very nice,
mana betekteb java aho

Unknown said...

Can you try to generate automatic clicks to earn money from Google Adsense? Google is smarter :(

Amr Kabardy said...

I don't think so, Mohab.. Because Google collects usage statistics and where the clicks came from.. So, they may discover your violation and... :D

Anonymous said...

Nice work Ahmed but i am having trouble running the bot on facebooks word challenge. Perhaps i am running the batch file incorrectly, which line to i add the letters in and are you sure there are no quotes? Must there be a space between the letters and number 4-6. Can some give more info pls? Thanks

Unknown said...

Please make sure you have the JRE installed, find it here http://www.java.com/en/download/index.jsp
Also please make sure you have it added to the PATH in your Environment variables, If you don't understand what I am saying please tell me :)
Finally, I recommend you to use the UPDATED version :)
Thanks and Glad that you are interested.

Anonymous said...

this isn't working for me!! =( i keep getting some sort of error message...what's wrong?

Unknown said...

Please read my previous comment.
If you had further problems kindly inform me.
Thanks,

Anonymous said...

I have the reccomended version of Java, but all I'm getting is a when i click on the MS-DOS file is a black screen flashing for 1 sec. What's wrong???

Anonymous said...

I have an up-to-date version of Java on my computer and i keep getting an error message everytime i try to run the bot...what's wrong??

Unknown said...

Hello, Sorry for the late reply :)

I want to do this test with you if you are running MS-Windows as an operating system.

- Click on Start --> Run
- Type cmd and press Enter
- A Black window will appear, Type java in it and press Enter

Just tell me what will you get as a result in this window.

Thanks,