开发者

How To Block Input in Java?

How can I block input from keyboard and mouse when my Java application is running. Like we block input in Auto开发者_如何学JAVAIt with BlockInput(1) , I also want to do same in Java.


I can only answer for a swing application. For your main frame you should have this

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

//or if you are using awt

 Frame frame = new Frame();
 frame.addWindowListener(new WindowAdapter() {
     // handle the window closing event here
  });


You can try This - JNativeHook, a global keyboard & mouse listener library for Java.


Create insance of transparent window (Window, not Frame or JFrame) and put it exactly on your application's window. User will not see anything (because it is transparent). But mouse and keyboard events will arrive to this transparent window.

Tip: the window should not be 100% transparent. In this case this trick does not work. put opacity 0.01.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜