kibkid Posted August 12, 2004 Share Posted August 12, 2004 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 More sharing options...
0 kjordan2001 Posted August 12, 2004 Share Posted August 12, 2004 KeyStroke probably isn't what you want unless you're making your own custom textbox. If you just want input, use System.in.read();. What exactly are you trying to do? Link to comment Share on other sites More sharing options...
0 kibkid Posted August 12, 2004 Author Share Posted August 12, 2004 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 More sharing options...
Question
kibkid
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:
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