“Windows键” + “其他键” - Java 不检测“其他键”
有没有与主题中的问题相对应的解决方案。如果我按 Windows 键 + 空格键,我会得到:
按键类型:Windows
我想应该是:
按键类型:Windows
键输入:空格
密钥已发布:Windows
keyReleased:空格
我的代码:
<Java component>.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
e.consume();
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("keyTyped: " + KeyEvent.getKeyText(e.getKeyCode()));
e.consume();
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased: " + KeyEvent.getKeyText(e.getKeyCode()));
e.consume();
}
});
谢谢!
Is there any solution that corresponds to the problem from the topic. If I press e.g. Windows key + Space, I get:
keyTyped: Windows
I guess it should be:
keyTyped: Windows
keyTyped: Space
keyReleased: Windows
keyReleased: Space
My code:
<Java component>.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
e.consume();
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("keyTyped: " + KeyEvent.getKeyText(e.getKeyCode()));
e.consume();
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased: " + KeyEvent.getKeyText(e.getKeyCode()));
e.consume();
}
});
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WINDOWS + Space
是 Windows 系统的有效全局热键,因此不会通知您的程序(并且永远不会)。它会检测到第一个笔画,因为WINDOWS
键不是热键(并且仅在释放时展开“开始”菜单。)这就是您也没有获得释放的原因。我不知道 Java 是否允许系统范围的挂钩,但您可能不得不使用 JNI,我认为您不想处理它。
WINDOWS + Space
is a valid global hotkey for the Windows system and therefore is not notifying your program (and will never.) It detects the first stroke becauseWINDOWS
key is not a hotkey (and only unfolds the Start menu upon release.) That's the reason you don't get the release either.I'm not aware if Java allows for system-wide hooks, but you'll probably have to mess with JNI, which I assume you don't want to deal with.