0

I have a swing Java application (A) that launches another application (B) using Runtime.getRuntime().exec() when a certain button is pressed.

Is it possible to set a certain Key Hook so that when the application (B) is open and active, it changes the buttons (for example, when you press "Q", in fact, the "H" button is pressed, and so on). And a similar situation for the mouse (for example, if "Mouse Mid" or "Mouse Wheel" is pressed, in fact another button is pressed, for example "T").

Ideally, it should work for all operating systems if possible, but Windows primarily.

Please tell me if it is possible to implement this at all, I will be glad to any advice or examples.

Neo
  • 69
  • 7
  • You need to work at the operating system level so the solution must be different for each platform, no? – Abra Nov 16 '20 at 14:44
  • @Abra Probably yes, I just never came across native functions and for me this is a new area. I read and watched a video about JNA / JNI / Jnativehook library. But in all the examples that I saw, it was only possible to catch the incoming key value. I do not know which direction to look in order to change and transfer it. – Neo Nov 16 '20 at 14:47

1 Answers1

1

As you want to hook with operating system's low level events. It could require JNI implementation that could be complex and will require OS libraries. There is one Maven library available at Github https://github.com/kristian/system-hook

It contains required libs as mentioned in Readme.md file. I haven't tried this. Hopefully it should work.

Ashish
  • 997
  • 6
  • 20
  • This is good library to catch key / mouse pressed, released and so on. But it's still not clear for me how to change incoming key to desired one? – Neo Nov 16 '20 at 17:10