kwhat / jnativehook

Global keyboard and mouse listeners for Java.
Other
1.75k stars 348 forks source link

GlobalScreen.postNativeEvent doesn't work for media keys on Linux #418

Open Lucas-Uchiha opened 2 years ago

Lucas-Uchiha commented 2 years ago

Hello, I'm using this library in a Kotlin project. This code works perfectly on a Windows machine:

GlobalScreen.postNativeEvent(
    NativeKeyEvent(
        2401, // id
        0,    // modifiers
        175,  // rawCode
        NativeKeyEvent.VC_VOLUME_UP,  // keyCode
        NativeKeyEvent.CHAR_UNDEFINED // keyChar
    )
)

but when I test the same code on any Ubuntu based system it doesn't work. I tried capturing the parameters using a NativeKeyListener and got the following:

GlobalScreen.postNativeEvent(
    NativeKeyEvent(
        2401,  // id
        8192,  // modifiers
        65299, // rawCode
        NativeKeyEvent.VC_VOLUME_UP,  // keyCode
        NativeKeyEvent.CHAR_UNDEFINED // keyChar
    )
)

but the problem persists. Up to version 2.2.1 absolutely nothing happens when I run the code but with version 2.2.2 I get this warning in the console:

ago. 17, 2022 6:23:10 PM com.github.kwhat.jnativehook.GlobalScreen postNativeEvent ADVERTÊNCIA: post_key_event [38]: Unable to lookup scancode: 57392

"ADVERTÊNCIA" means "warning" in portuguese.

I used volume up as an example, but the same problem occurs with other media keys. Any idea why this is happening?

kwhat commented 2 years ago

2.2.2 had an overhaul for event posting which is why you get a warning with that version. It sounds like the lookup table may just be missing the media keys. I'll take a look in a bit and get back to you. Remind me if I forget.

On Wed, Aug 17, 2022, 2:58 PM Lucas Uchiha @.***> wrote:

Hello, I'm using this library in a Kotlin project. This code works perfectly on a Windows machine:

GlobalScreen.postNativeEvent(

NativeKeyEvent(

    2401, // id

    0,    // modifiers

    175,  // rawCode

    NativeKeyEvent.VC_VOLUME_UP,  // keyCode

    NativeKeyEvent.CHAR_UNDEFINED // keyChar

)

)

but when I test the same code on any Ubuntu based system it doesn't work. I tried capturing the parameters using a NativeKeyListener and got the following:

GlobalScreen.postNativeEvent(

NativeKeyEvent(

    2401,  // id

    8192,  // modifiers

    65299, // rawCode

    NativeKeyEvent.VC_VOLUME_UP,  // keyCode

    NativeKeyEvent.CHAR_UNDEFINED // keyChar

)

)

but the problem persists. Up to version 2.2.1 absolutely nothing happens when I run the code but with version 2.2.2 I get this warning in the console:

ago. 17, 2022 6:23:10 PM com.github.kwhat.jnativehook.GlobalScreen postNativeEvent ADVERTÊNCIA: post_key_event [38]: Unable to lookup scancode: 57392

"ADVERTÊNCIA" means "warning" in portuguese.

I used volume up as an example, but the same problem occurs with other media keys. Any idea why this is happening?

— Reply to this email directly, view it on GitHub https://github.com/kwhat/jnativehook/issues/418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFFCRD4RYKKZA74J75CESDVZVOADANCNFSM563CCD7Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>