开发者

Global hotkeys for WindowsFormApplications

开发者 https://www.devze.com 2023-01-28 15:21 出处:网络
How can I execute a function, when user clicks specific button? E.g. when I want to count, how many times user w开发者_开发技巧ill hit \'A\' button during writing (or Ctrl+C combination).

How can I execute a function, when user clicks specific button? E.g. when I want to count, how many times user w开发者_开发技巧ill hit 'A' button during writing (or Ctrl+C combination).

My app should work in background.


I think that there is no "legal" way to do this because you can listen to event happening into your window and not outside. I'd be happy to know that I am wrong and there is a "right" way to do this.

I can suggest you a trick (workaround). Create transparent full screen window. User does not see it but you can catch all events that are happening withing its bounds. Every time you catch keyboard event do the following: 1. remember the event 2. close the window 3. use class Robot to replay the event. 4. restore the transparent window again.

I believe that computers are fast enough to do all these so fast that users cannot see anything.


I found this solution to work just great on windows. It does not require you to install any software like JIntelliType. Note that this is 32 bit dll and you can recompile for 64-bit JVM is do desire. All credits to original author of the blog.

0

精彩评论

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

关注公众号