@marlin
2016-08-13T12:28:23.000000Z
字数 863
阅读 2637
工具
tool
windows全局事件
当时用windows系统时,可能会遇到监听快捷键的需要。即焦点不在当前窗体内,但仍需要监控快捷键,比如qq的截图(ctrl+alt+A)等。
使用的小工具是jintellitype,其在github上的项目见这里。原理如下:
JIntellitype is an API for interacting with Microsoft Intellitype keyboard commands as well as registering for Global Hotkeys in your application. The API is a Java JNI library that uses a DLL to do all the communication with Windows. This library ONLY works on Windows.
Have you ever wanted to have CTRL+SHIFT+G maximize your Swing application on the desktop even if that application did not have focus? Now you can by registering a Windows Hotkey combination your application will be alerted when the combination you select is pressed anywhere in Windows.
JIntellitype是与Microsoft Intellitype 键盘命令交互的API,它通过在应用程序中注册全局热键(Hotkey)实现。这个API是一个JNI的库,所有与windows的交互都是通过DLL进行。而且这个库只在windows下工作。
如果你曾希望利用CTRL+SHIFT+G将你的Swing程序在桌面上放大,即使它并没有聚焦,那么你可以在windows上注册热键,并与你的应用程序绑定,这样无论何时何地当你绑定的热键在windows中被按下时,你的应用程序都能够接收到这个通知。