I have a Java function in which I want to test if the control key is being held down. How can I do that?
Edit: I am using swing for gui.
It depends on several things.
If you're running the Java program as a console program (text based) you have to test for approriate bits in the received chatracter.
Otherwise, you should look at InputEvents for the appropriate GUI classes, eg, http://docs.oracle.com/javase/6/docs/api/java/awt/event/InputEvent.html.
Have a look at this tutorial: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html