gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:33:32 27 4
gpt4 key购买 nike

我无法将 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

我是不是漏掉了什么?

最佳答案

您可能忘记阅读 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 - 无法将 Control-Backspace 映射到 KeyStroke,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6390495/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com