开发者

how to disable system keyboard handling in Java AWT Application?

How can i disable such keys and their combinations开发者_Python百科 as, for example, Alt ; Alt + F4 and others in my Java AWT application?

E.g. my KeyboardListener should handle that keys as 'usual' keys and combinations without closing window or entering window menu.


One way is to create a program in "kiosk mode", something that requires more than Java to achieve (such as JNA or JNI). If you google this or search this site for this, you'll find out more about it. If I were using your code, though, I'd be very frustrated and perhaps angry, unless this were being run on a dedicated kiosk terminal.

Edit: Another option is as per this thread: java-full-screen-program-swing-tab-alt-f4:

 window.setExtendedState(Frame.MAXIMIZED_BOTH); //maximise window
 window.setUndecorated(true); //remove decorations e.g. x in top right
 window.setAlwaysOnTop(true);

Edit 2: and this brute-force method: Remove the possibility of using Alt-F4 and Alt-TAB in Java GUI


Found this solution:

  • for Tab - use Frame.setFocusTraversalKeysEnabled(false);

  • for Alt - add keyEvent.consume(); at the end of each key event handling code block

Then, to find out if Alt or Ctrl key is pressed - use keyEvent.isAltDown() and keyEvent.isControlDown() methods of keyPressed or keyReleased events.

Thanks, @Hovercraft , for your quick response!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜