SWT 错误地检测组合键
SWT incorrectly detects key combinations
我的 Windows 10 上有两种语言(英语和俄语)。我运行下面的代码片段:
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(640, 480);
shell.setLocation(500, 250);
shell.setText("SWT");
FillLayout layout = new FillLayout();
shell.setLayout(layout);
shell.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
List<String> keys = new ArrayList<>();
if ((e.stateMask & SWT.CTRL) != 0) {
keys.add("Ctrl");
}
if ((e.stateMask & SWT.ALT) != 0) {
keys.add("Alt");
}
if ((e.stateMask & SWT.SHIFT) != 0) {
keys.add("Shift");
}
keys.add(Character.toString((char) e.keyCode));
System.out.println(keys);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
当语言设置为英语并按下 Right Alt + T
时,程序正确打印 [Alt, t]
.
但是,当我将语言切换为俄语并按 Right Alt+T
时,程序会打印 [Ctrl, Alt, t]
。这是不正确的,因为我没有按 Ctrl。
这很烦人,因为我们的 Eclipse RCP 键绑定(例如 Alt+F7
或 Alt+Shift+F5
)无法正常工作。
知道 SWT 为何错误检测 Ctrl
吗?
我正在使用来自最新 Eclipse 4.6 (SWT 3.105.0) 的 SWT。
您是否尝试过在 windows 10.
中禁用更改语言的快捷方式
由于历史原因,非美式键盘布局中使用的AltGr
(右Alt
)键被操作系统自动转换为Ctrl + Alt
(see Wikipedia about this ).
所以这与 SWT
没有特别的关系。
为避免此问题,用户应使用标准 Alt
(左 Alt
)键。
我的 Windows 10 上有两种语言(英语和俄语)。我运行下面的代码片段:
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(640, 480);
shell.setLocation(500, 250);
shell.setText("SWT");
FillLayout layout = new FillLayout();
shell.setLayout(layout);
shell.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
List<String> keys = new ArrayList<>();
if ((e.stateMask & SWT.CTRL) != 0) {
keys.add("Ctrl");
}
if ((e.stateMask & SWT.ALT) != 0) {
keys.add("Alt");
}
if ((e.stateMask & SWT.SHIFT) != 0) {
keys.add("Shift");
}
keys.add(Character.toString((char) e.keyCode));
System.out.println(keys);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
当语言设置为英语并按下 Right Alt + T
时,程序正确打印 [Alt, t]
.
但是,当我将语言切换为俄语并按 Right Alt+T
时,程序会打印 [Ctrl, Alt, t]
。这是不正确的,因为我没有按 Ctrl。
这很烦人,因为我们的 Eclipse RCP 键绑定(例如 Alt+F7
或 Alt+Shift+F5
)无法正常工作。
知道 SWT 为何错误检测 Ctrl
吗?
我正在使用来自最新 Eclipse 4.6 (SWT 3.105.0) 的 SWT。
您是否尝试过在 windows 10.
中禁用更改语言的快捷方式由于历史原因,非美式键盘布局中使用的AltGr
(右Alt
)键被操作系统自动转换为Ctrl + Alt
(see Wikipedia about this ).
所以这与 SWT
没有特别的关系。
为避免此问题,用户应使用标准 Alt
(左 Alt
)键。