...

View Full Version : Java KeyListener



sznsx
02-12-2005, 07:14 AM
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...



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 !!!!!!!!!!!

sznsx
02-12-2005, 04:48 PM
guess not, alright then thanks anyway coding forums !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum