Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

How do I use keyboard input to move an object?

+4 votes
I know how to use the mouse to control an object by using getMouseX and getMouseY but was wondering if any one knew how to do this using keyboard as input. I know there is a method called getKeyboardInput but that doesn't let me choose specific keys (that I am aware of). Let me know if you have any ideas
asked Feb 12, 2015 in (Winter 14) by Nowlan Savage (100 points)

1 Answer

+1 vote
if (panel.checkKeyboardInput()) {

    String pressedKey = panel.getKeyboardInput();

    //  find out which key it was & do stuff here...


See also: the MouseKeyboardTesting.java on Moodle.
answered Feb 12, 2015 by Forrest Stonedahl (100 points)