i am trying to use jnativehook library in my project.i want to get a simple data (e.g Mouse Clicked: 2) instead of long loging data that jnativehook is Produced like:
May 31, 2015 9:39:04 PM org.jnativehook.GlobalScreen$NativeHookThread enable INFO: process_button_pressed [339]: Button 1 pressed 2 time(s). (293, 661)
May 31, 2015 9:39:04 PM org.jnativehook.GlobalScreen$NativeHookThread enable
Mouse Clicked: 2
INFO: process_button_released [361]: Button 1 released 2 time(s). (293, 661)
If you want to remove that logging spam from JNativeHook:
// Clear previous logging configurations.
LogManager.getLogManager().reset();
// Get the logger for "org.jnativehook" and set the level to off.
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);
Adding this to, for example. Your main class construct with remove (almost) all logging. Now let's detect yourself the events and print some basic information.
First, you have to register the NativeHook:
GlobalScreen.registerNativeHook();
Then bind some listener to it, for example:
GlobalScreen.getInstance().addNativeKeyListener(new YourMainClass());
And then override the JNativeHook event methods like this:
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
System.out.Println(((char) e.getKeyCode()) + " was pressed.")
}
Check out: JNativeHook GitHub, you will find some sample code (for example Global Mouse Listener and documentation about it's events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With