Java – cannot map control backspace to keystroke

I can't map the control backspace key to keystroke The following is meaningless 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:

Press back_ SPACE

Press back_ SPACE

Press back_ SPACE

Did I miss anything here?

Solution

You may forget to read documentation Note that the modifier mask comes 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);
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>