Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting keyboard input.

807603Mar 2 2007 — edited Jan 30 2008
Hello I am an amateur (first year university) Java programmer. Recently I have been playing around with some of the functions in Java and came across the Robot class which I'd like to do more with.

What I want to happen is something along these lines:

1. A Key is pressed, robot does function A
2. When Key is released robot stops doing function A
3. A different key is pressed, robot does Function B
4. When Key is released robot stops doing function B

I managed to get the robot class working only if I use it in the main method and make it do a few things.

I have done keyboard input before using KeyEvent and KeyListener, but the problem here is there is no actual gui or something for it to use as a component. Is there a way I can hook it on to the raw state of the keyboard or something?

If there isn't, then is there a different way to go about getting the state of the keyboard?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 27 2008
Added on Mar 2 2007
5 comments
244 views