Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove the logging data from JNativeHook library [closed]

Tags:

java

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)

like image 631
Kingtak Avatar asked May 31 '15 17:05

Kingtak


1 Answers

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.

like image 152
Yayotrón Avatar answered Sep 19 '22 21:09

Yayotrón