Checking the keyboard state inside an applet

Hi,

I’m trying to write a little space shooter game in a java applet to put on my website.

In previous games the action is a little more sedate and have had to worry about quick/exact responses from the keyboard. So have just add a KeyListener and checked for KeyPresses like below

public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_KP_LEFT ||
e.getKeyCode() == e.VK_LEFT) {

    ship.moveLeft();
}

}

But for a fluid game i need something alot smarter :slight_smile: I guess I’m looking for a way of checking the keyboard state or something, so i could poll the keyboard and see at any stage which keys are pressed. eg. Left arrow, Up arrow and the control key

Does anyone know an easyish way of getting this information from inside an applet? or can point me to somewhere that might have a bit of info on the topic.

Thanks

Andy

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1065784010;start=8#8

Says it all :slight_smile:

Btw the “&0xFF” thingy ensures that it stays within the array-bounds (only a handfull of keys like ä,ü,ö or other unusual letters have a higher KeyCode).

Edit:

Oh… and welcome to the board :slight_smile:

Cool, thanks

I did do a search for “keyboard input” on the forums. I mustn’t have checked that forums in the list to search. :-[

anyways thanks for doing my leg work hehe.

Well, I’d known a better search phrase… I used “controls[” ;D

The other option is to go to a Java Web Start application and use JInput :slight_smile:

[quote]I did do a search for “keyboard input” on the forums. I mustn’t have checked that forums in the list to search. :-[
[/quote]
Ah. As default the search page only looks at the last week of posts - that’s probably why you didn’t find anything! :wink: