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.
Use KeyEvent. getKeyChar() and KeyEvent. getKeyCode() to find out which key the user pressed.
The Windows on-screen keyboard is a program included in Windows that shows an on-screen keyboard to test modifier keys and other special keys. For example, when pressing the Alt , Ctrl , or Shift key, the On-Screen Keyboard highlights the keys as pressed.
use the "isControlDown()" boolean:
public void keyPressed (KeyEvent e)
{
System.out.println(e.isControlDown());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With