I'm trying to write quite simple program in Java - when user click left mouse button it will autoclick until released, but only if toggled before with keyboard key. I have no problem with this autofire part, but I dont know how to detect keyboard press, and mouse button press when my aplication doesn't have focus. Is there some simply way to do it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
On a side note - Are you creating macro for game?
You can download jNativeHook https://code.google.com/p/jnativehook/ and hook global listener to globalScreen that way it doesn't matter if you have focus over application.
Then you can use it like normal swing/fx listener.
CAUTION
Make sure that you unhook it correctly otherwise after some hooks it might be blocked and you will have to restart the PC to hook it again (fixed in future release).
If you are doing a macro for a game you might have a problem when focused on window - some fullscreen games and even in windowed mode, at least from my personal experience. Robot will also fail in some games to execute event.