Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNativeHook how do you keep from printing everything that happens?

Tags:

java

So I need jnativehook to detect when a copy/paste is preformed as a copy/paste backup application, and since this is a console application I don't want it getting spammed by cursor position and keystrokes, I just need it to sit there quitely and listen for copy/paste. But instead this is happening

    Oct 25, 2014 10:21:54 AM org.jnativehook
INFO: hook_event_proc [405]: Mouse moved to 3468, 829.

Oct 25, 2014 10:21:54 AM org.jnativehook
INFO: hook_event_proc [405]: Mouse moved to 3468, 828.

Oct 25, 2014 10:21:54 AM org.jnativehook
INFO: hook_event_proc [405]: Mouse moved to 3467, 827.

Oct 25, 2014 10:21:54 AM org.jnativehook
INFO: hook_event_proc [405]: Mouse moved to 3467, 826.

Oct 25, 2014 10:21:54 AM org.jnativehook
INFO: hook_event_proc [405]: Mouse moved to 3467, 825.

Oct 25, 2014 10:21:55 AM org.jnativehook
INFO: hook_get_multi_click_time [218]: XtGetMultiClickTime: 200.

Oct 25, 2014 10:21:55 AM org.jnativehook
INFO: hook_event_proc [290]: Button 1  pressed 1 time(s). (3467, 825)

Oct 25, 2014 10:21:55 AM org.jnativehook
INFO: hook_event_proc [358]: Button 1 released 1 time(s). (3467, 825)

Oct 25, 2014 10:21:55 AM org.jnativehook
INFO: hook_event_proc [372]: Button 1 clicked 1 time(s). (3467, 825)

Is there a way to turn that off? I have the basic Native Hook registration and error catching as well as the three empty listening events.

try {
            GlobalScreen.registerNativeHook();
        } catch (NativeHookException n) {

            System.err.println("JNativeHook could not be registered");
            System.err.println(n.getMessage());
            System.exit(1);
        }

        GlobalScreen.getInstance().addNativeKeyListener(new Main());
like image 760
Unknown Avatar asked Oct 25 '14 17:10

Unknown


2 Answers

From the usage wiki on the JNativeHook github.

// 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 these lines of code to your main object's constructor, for example, would keep the almost all logging from being displayed in your console. This however, only applies to JNativeHook version 1.2 (newest).

There is also an option to only display warnings and errors as well.

like image 104
KimJungSkill Avatar answered Nov 08 '22 05:11

KimJungSkill


... by reading the documentation. JNativeHook uses java.util.logging for console output. Note that you cannot disable to copyright via the logger by design.

like image 32
Alex Barker Avatar answered Nov 08 '22 05:11

Alex Barker