So I just started learning Java this year and I'm trying to take on what I believe to be a simple project.

I'm trying to write a program that will control my keyboard and beat the Snake web app on facebook. To do this I had a plan of writing code using the robot class to control my keys but I've been running into a few problems.

First and foremost, is there a way to tell java to switch to my Firefox window when it starts? Right now I'm having to try to click run and then quickly click on my firefox browser in order for the keystrokes to register in Firefox.

Secondly, would the best way to do this simply be by using robot.delay(int ms); in between key presses? This would naturally take quite a bit of trial and error to get the times down just right so I was just wondering if there would be any better way to do this.

Thanks

December 4th, 2010, 05:48 PM

helloworld922

Re: Creating a java program to "Beat" Snake web app?

You could program your robot to click in a place that the firefox icon is (or launch a new firefox program), then firefox would have the focus and you can send keypresses to firefox.

December 5th, 2010, 12:36 AM

AkOndray

Re: Creating a java program to "Beat" Snake web app?

ok well that worked perfectly, but I've already ran into another problem. No matter what I do, Java seems to have internal lag which is causing the program to fail. Sometimes I'll run it and it will work fine, other times it won't turn fast enough and because of this it will crash into a wall. Any thoughts on how to fix this?