重新获得窗口焦点后,Java keyPressed 事件停止工作
我的 KeyPressed 事件有一点问题。 如果我启动我的应用程序,一切都会正常。如果我然后对窗口进行散焦,然后重新聚焦,则 KeyEvent 不会触发。我按“Shift + Tab”后,它再次起作用。
@Override
public void keyPressed(KeyEvent e) {
// Prints the keycode
System.out.println("Key-Pressed: " + e.getKeyCode());
}
这些只是为了显示窗口是否处于焦点。
@Override
public void windowGainedFocus(WindowEvent e) {
System.out.println("Window Focus Gained");
}
@Override
public void windowLostFocus(WindowEvent e) {
System.out.println("Window Focus Lost");
}
这里有一个小视频,显示了我所描述的内容: https://youtu.be/j0VKQKUjJGc
我希望有人可以帮我解决这个问题,提前谢谢你。
I have a little Problem with my KeyPressed Event.
If I launch my App everything works fine. If I then Defocus the Window, and later Refocus, the KeyEvent does not fire. After I press "Shift + Tab", It works again.
@Override
public void keyPressed(KeyEvent e) {
// Prints the keycode
System.out.println("Key-Pressed: " + e.getKeyCode());
}
These are just, for showing if the Window is in focus.
@Override
public void windowGainedFocus(WindowEvent e) {
System.out.println("Window Focus Gained");
}
@Override
public void windowLostFocus(WindowEvent e) {
System.out.println("Window Focus Lost");
}
Here a small Video that shows what I described: https://youtu.be/j0VKQKUjJGc
I hope some one can help me with this, thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有没有尝试过:
Have you tried: