Q:

Java-check if control key is being pressed

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. 

A:

use the "isControlDown()" boolean:
public void keyPressed (KeyEvent e)
{
     System.out.println(e.isControlDown());
}

A:

The code above works only if the only thing pressed is the control key.   If they have ctrl and some other button is pressed (perhaps) accidently, it won't capture. 
You can check exactly for just the ctrl key
// Are just the CTRL switches left on
if(evt.getModifiers() == InputEvent. CTRL_MASK) {
    System.out.println("just the control key is pressed);
}

When simulating multiple keys pressed, you use the or bit operator.   To simulate holding both the left button and ctrl key, look for this. 
// Turn on all leftButton and CTRL switches
int desiredKey = InputEvent. BUTTON1_MASK | InputEvent. CTRL_MASK;  

When checking if the ctrl key is down you may do this
// If we turn off all switches not belonging to CTRL, are all the CTRL switches left on
if((evt.getModifiers() & InputEvent. CTRL_MASK) == InputEvent. CTRL_MASK) {
    System.out.println("Control Key is pressed and perhaps other keys as well");
}

You can also check if both the left button and ctrl mask are pressed
// If we turn off all switches not belonging to leftButton or CTRL, are all the leftButton and CTRL switches left on
if((evt.getModifiers() & desiredKey) == desiredKey) {
    System.out.println("left button and control keys are pressed and perhaps others as well");
}

Suppose you have this:
A | B

You should think of it like this.   A has a control panel with a bunch of switches on.   B also has a control panel with a bunch of switches on.   The job of "| B" is to do the minimum work necessary to make sure all B's switches get turned on. 
Suppose you have this:
A & B

The job of "& B" is to do the minimum work necessary to turn off any switches which aren't B's.