Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Java KeyListener

    Hello All !

    I have the following code where I am listening for the user to press the keys "Up, Down, Left, Right".... It lets me know when each key is pressed however I need more information... I would like to know when the arrow key is pressed and then also know when the arrow key is released...

    Code:
            
    private class KeyHandler extends KeyAdapter {
      public void keyPressed(KeyEvent e) {
          int keyCode = e.getKeyCode();
              if (keyCode == e.VK_DOWN)
                   System.out.println(keyCode);
              if (keyCode == e.VK_UP)
                   System.out.println(keyCode);
              if (keyCode == e.VK_LEFT)
                   System.out.println(keyCode);
              if (keyCode == e.VK_RIGHT)
                   System.out.println(keyCode);
      }
    }
    So something like

    > if (VK_DOWN pressed) blah blah
    > if (VK_DOWN released) blah blah
    > if (VK_UP pressed) blah blah
    > if (VK_UP released) blah blah
    .....
    continued for the other arrow keys

    T H A N K ----- Y O U !!!!!!!!!!!

  • #2
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    guess not, alright then thanks anyway coding forums !


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •