0

Is there a way to detect key input when the window is not active? That is, another application is running but the program is triggered when say the F9 key is pressed or something along those lines.

Is that possible or is java not compatible for such functions? From what I found java can't get input unless it's the active window.

Note: I typically use keylistener, which seems to stop working (with good reason) when I am not actively using the program.

Bhavik Ambani
  • 6,557
  • 14
  • 55
  • 86
imbuedHope
  • 508
  • 3
  • 14
  • 1
    There is no "native Java" way to accomplish this. You would require a JNI/JNA solution to achieve this – MadProgrammer Dec 04 '12 at 05:47
  • @MadProgrammer any recommendations on where to look for more info? – imbuedHope Dec 04 '12 at 05:51
  • 1
    @imbuedHope http://code.google.com/p/jnativehook/ – FThompson Dec 04 '12 at 05:54
  • ["global" KeyListener using JNA](http://stackoverflow.com/questions/6174119/global-keylistener-using-jna), [JNA: key listener + JFrame](http://stackoverflow.com/questions/9821429/jna-key-listener-jframe), [jnativehook](http://code.google.com/p/jnativehook/) – MadProgrammer Dec 04 '12 at 06:22

1 Answers1

0

It sounds like you want low level keyboard hooks.

Get global keyboard input with Java

It's not directly possible in Java (i.e. with pure Java code), but you could reference other libraries (or make your own) to acheieve this. A quick google search gives a lot of references and free/open libraries that can give you keyboard and mouse hooks (both very handy).

Hope that helps.

Community
  • 1
  • 1
txtechhelp
  • 6,625
  • 1
  • 30
  • 39