Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

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

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a java program to "Beat" Snake web app?

    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


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

Similar Threads

  1. Replies: 6
    Last Post: November 12th, 2010, 03:40 AM
  2. Replies: 2
    Last Post: October 29th, 2010, 03:14 AM
  3. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 07:35 AM
  5. Replies: 2
    Last Post: October 29th, 2009, 06:13 PM