编程语言
首页 > 编程语言> > java – 无法将Control-Backspace映射到KeyStroke

java – 无法将Control-Backspace映射到KeyStroke

作者:互联网

我无法将Control-Backspace键映射到KeyStroke.以下对我没有意义.

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);
    }
}

输出:

按下BACK_SPACE

按下BACK_SPACE

按下BACK_SPACE

我在这里错过了什么吗?

解决方法:

您可能忘记阅读documentation.请注意,修改器蒙版来自与按下的键不同的位置.

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);
    }
}

标签:java,swing,keyboard-events,key-bindings,backspace
来源: https://codeday.me/bug/20190730/1577982.html