无法将 Control-Backspace 映射到 KeyStroke

发布于 2024-11-15 18:13:36 字数 703 浏览 3 评论 0原文

我在将 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);
    }
}

输出:

shift 按下 BACK_SPACE

按下 BACK_SPACE

按下 BACK_SPACE

我在这里遗漏了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘初心 2024-11-22 18:13:36

您可能忘记阅读

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

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文