Multiple keys in java

Started by
1 comment, last by googa 18 years, 10 months ago
Hi, Can anyone help me.. I want to know how is the best way to know about a key state in java, if it´s pressed or not. (I´m a c++ programmer, java beginner). like GetKeystate() in c++.. THANKS A LOT!
What about an Addictive FREE Turn-Based Puzzle/Strategy Game, with a Growing Community Available to Play right now?<a href="http://www.wonderquest.co.nr"><( ) -Hurrahh!/a> <a href="http://www.wonderquest.co.nr"><( ) -Yes!/a> <a href="http://www.wonderquest.co.nr"><( ) -Ai Caramba!/a>
Advertisement
Attach a KeyListener to the component you want to listen to key events from (usually your Canvas or Window object which you're doing your drawing on). Use the events generated to set flags which you can read in your other (game loop) thread.

If you want something closer to GetKeyState(), then try using LWJGL which is generally closer to regular C++ framework style, and provides an easy isKeyDown() method.
Thanks Orangytang, by the way do you know how can i access the main class from inside another one?
What about an Addictive FREE Turn-Based Puzzle/Strategy Game, with a Growing Community Available to Play right now?<a href="http://www.wonderquest.co.nr"><( ) -Hurrahh!/a> <a href="http://www.wonderquest.co.nr"><( ) -Yes!/a> <a href="http://www.wonderquest.co.nr"><( ) -Ai Caramba!/a>

This topic is closed to new replies.

Advertisement