0

Is it possible to bind a global key listener for a Java program?

Like windows key binds.

My objective is to when I am in a game, I could, for example, change my current music by pushing F2 or F3.

Sastrija
  • 3,284
  • 6
  • 47
  • 64
  • Is JNI out of the question? Does it need to be pure Java? Also, do you want it to respond to these global key bindings only when minimized, or do you want it to respond at any time, including when the application is inactive (does not have focus)? – user314104 Nov 20 '11 at 05:37
  • anything would work, i just need it to respond when it dont have focus, like a game is openned and program still running (anytime) – user1056053 Nov 20 '11 at 05:42

1 Answers1

1

See the answer for Java System-Wide Keyboard Shortcut. If you want it to apply globally (and not just when the container is minimized), then this should do it. If you want it only for when your container is minimized, then you can take that solution and see if your container is minimized (Frame.getState()).

Community
  • 1
  • 1
user314104
  • 1,528
  • 14
  • 31
  • Just a commentary on the answers provided there -- watch out if you're using 64-bit versions of Windows and attempting to do DLL injections. Trying to inject a 32-bit DLL into a 64-bit process's address space would get really nasty. – user314104 Nov 20 '11 at 05:49