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.
I found one solution which solves my problem: I declare a global variable
boolean controlStatus=false;
Then in the event for keyPressed on the jTextField:
if(evt.getKeyCode()==KeyEvent.VK_CONTROL)
controlStatus=true;
In the event for keyReleased:
if(evt.getKeyCode()==KeyEvent.VK_CONTROL)
controlStatus=false;
Then I can access the global variable to check if the control key is being held down.