Sign in to follow this  
googa

Multiple keys in java

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanks Orangytang, by the way do you know how can i access the main class from inside another one?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this