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: [Request/Help] Holding the keyboard arrow for 0.5 mili second etc ...

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question [Request/Help] Holding the keyboard arrow for 0.5 mili second etc ...

    Hello! Thanks for helping me if you decide to

    But yeah, i am trying to do the following:

    press Left Arrow Key for 1 second, then press up arrow key for 1 second then continue rest of the code!


    I have looked all over the internet and i cannot find anything... when i try to use

    robot.keyPress(KeyEvent.VK_LEFT);
    robot.keyPress(KeyEvent.VK_UP);
    // --> Continue rest of the application


    it holds on left arrow key and stays looping forever... i even tried using timers but im i guess im not good enough to do that
    Please help me, my kind friends!


    /edit 2/

    never mind.. i did it using a differe
    long t= System.currentTimeMillis();
    long end = t+5000;
    while(System.currentTimeMillis() < end) {
    robot.keyPress(KeyEvent.VK_LEFT);
    }

    but now im wondering, how do i stop it from holding that key after the event is done?
    Last edited by Jangan; February 2nd, 2012 at 08:50 PM.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: [Request/Help] Holding the keyboard arrow for 0.5 mili second etc ...

    Well if you looked at the Robot's class API, you would see this nice method:

    public void keyRelease(int key)

    Which
    Quote Originally Posted by Java SE 6 Robot API
    Releases one or more mouse buttons.

  3. The Following 2 Users Say Thank You to Tjstretch For This Useful Post:

    chronoz13 (February 3rd, 2012), Jangan (February 3rd, 2012)

  4. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Request/Help] Holding the keyboard arrow for 0.5 mili second etc ...

    could you please explain a little more?

    how do i use this in my little code to stop the left arrow key?

Similar Threads

  1. Moving an image around the screen using the arrow keys.
    By nemo in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 19th, 2013, 01:08 AM
  2. [SOLVED] Arrow keys to navigate a maze in a console program
    By B25Mitch in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 31st, 2012, 04:58 PM
  3. Replies: 0
    Last Post: November 16th, 2011, 08:29 AM
  4. Clueless on request.getContextPath()
    By ram.java in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 29th, 2011, 01:07 PM
  5. video game problem - delay in response to arrow key presses
    By gib65 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 17th, 2010, 08:39 PM