kwhat / jnativehook

Global keyboard and mouse listeners for Java.
Other
1.73k stars 345 forks source link

Distinguish between virtual input and human input #461

Open freakzbc opened 5 months ago

freakzbc commented 5 months ago

Key sources include real human keyboard input and java.awt.Robot virtual input. How do I distinguish them when using keyListener?

I tried to distinguish by these properties, but they are the same in both cases.

    public void nativeKeyPressed(NativeKeyEvent e) {

        System.out.println("--------------------------");
        System.out.println(e.getKeyCode());
        System.out.println(e.getKeyLocation());
        System.out.println(e.getWhen());
        System.out.println(e.getKeyChar());
        System.out.println(e.getSource());
        System.out.println(e.getID());
        System.out.println(e.getModifiers());
        System.out.println(e.getRawCode());
        System.out.println("==========================");
    }
kwhat commented 5 months ago

This has been resolved upstream and will be available in 2.3

wysnxzm commented 1 week ago

This has been resolved upstream and will be available in 2.3

I really need this feature, waiting for you

kwhat commented 1 week ago

Unfortunately there is only one of me. Some code to do this has been committed upstream but I haven't figured out how I am going to integrate it. Most of my time is being spent on the dumpster fire that is Wayland and the 1000s of lines of code it takes to figure out the simplest of things like the x,y coordinates of the mouse.

I could probably make some preview release of 2.3 if that would help. They wont be in Maven Central, but you could use them locally.

Let me know.

wysnxzm commented 1 week ago

Unfortunately there is only one of me. Some code to do this has been committed upstream but I haven't figured out how I am going to integrate it. Most of my time is being spent on the dumpster fire that is Wayland and the 1000s of lines of code it takes to figure out the simplest of things like the x,y coordinates of the mouse.

I could probably make some preview release of 2.3 if that would help. They wont be in Maven Central, but you could use them locally.

Let me know.

You can try to find some inspiration in autohotkey. In fact, I have raised similar questions and suggestions before.

kwhat commented 1 week ago

You can try to find some inspiration in autohotkey. In fact, I have raised similar questions and suggestions before.

I've read though their code and I've got a working libevent implantation, the hard parts are the bits around the edges like absolute mouse position, language support, monitor count and configuration. Simple things like getting the mouse double click interval are literally impossible on Wayland. GTK has a proprietary value, but KDE does not and trying to support the 9+ compositors that currently exist is next to impossible.