Reputation: 4859
I am having trouble mapping the Control-Backspace key to a KeyStroke. The following makes no sense to me.
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
public class TestControlBackspace {
public static void main(String[] args) {
KeyStroke ks1 = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.VK_CONTROL);
KeyStroke ks2 = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.VK_SHIFT);
KeyStroke ks3 = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
System.out.println(ks1);
System.out.println(ks2);
System.out.println(ks3);
}
}
Output:
shift pressed BACK_SPACE
pressed BACK_SPACE
pressed BACK_SPACE
Am I missing something here?
Upvotes: 3
Views: 1509
Reputation: 3761
You probably forgot to read the documentation. Note that the modifier masks come from a different location than the key pressed.
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
public class TestControlBackspace {
public static void main(String[] args) {
KeyStroke ks1 = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, InputEvent.SHIFT_DOWN_MASK);
KeyStroke ks2 = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK);
KeyStroke ks3 = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
System.out.println(ks1);
System.out.println(ks2);
System.out.println(ks3);
}
}
Upvotes: 7