• 0

Using the KeyStroke class in java


Question

Hi guys, I'm making this simple game and at one point I need to know how to identify which key the user pressed.

In c++ you can find out by using the getch();

I'm doing this in Java though:

this is what am doing:

KeyStroke hey = KeyStroke.getKeyStrokeForEvent(KeyEvent);
System.out.println(hey);

That doesn't work specially because I don't know what to put in the parameter for KeyEvent if I put

KeyEven.KEY_TYPED I get an error because this is an int and not an anEvent.

What am I doing wrong and how can I achieve this?

Thanx guys

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi the reason I need this is coz I want to do a little AI in my game and I need the program to react to each user input differently, however the input could be any key pressed.

So the program must be able to react as soon as a key is pressed (and is supposed to recognize the key).

The thing that the user should not have to press enter, but the act of pressing the key should be enough.

thanx

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.