This key event is not working. The same code is working for,
VK_SPACE
Its not working for control
private void jTextArea1KeyPressed(java.awt.event.KeyEvent evt) {
if ((evt.getKeyChar() == KeyEvent.VK_CONTROL)) {
System.out.println("CONTROL IS PRESSED");
}
}
Don’t use
getKeyCharin combination with thoseVK_constants. UsegetKeyCodeinstead.getKeyCharis for printable keys only, which result in a character being printed in normal operations.getKeyCode, on the other hand, is intended to give you the code (i.e. theVK_constant) of the key pressed, even if there is no associated character (as in the case of Ctrl).See also this answer.