views:

78

answers:

1

Hi guys,

I need to detect when the mouse or keyboard activity is present. My application runs in the background (tray) and I need to detect this activity even when my app isn't in focus.

I don't need to know what keys were pressed, but simply WHEN they are pressed.

Can I do this with just Java? I have read some solutions using JNI and C++/C but they seem to be OS specific. Is there an easy solution to this that will work with Windows, Linux, and Mac?

Thanks!

+2  A: 

Since JNI is required, which relys on the OS specific APIs, the only way would be to have an implementation for each supported OS and load it dynamically after detecting the OS in you application.

For Windows Java Global Keyboard/Mouse Hook – JNI

stacker