kwhat / jnativehook

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

Posting mouse wheel event ignores coordinates in Linux #397

Closed Chae4ek closed 2 years ago

Chae4ek commented 2 years ago

I have a problem with posting a NativeMouseWheelEvent in Linux. It seems the passing coords are ignored and the mouse cursor jumps to the top of the screen, but then jumps at the start position. It looks like this issue #76. I think it's even a similar bug. As I understand it, when posting mouse button events in X11, the same method is used, but when receiving event->data.mouse there are no checks whether it's a wheel event: https://github.com/kwhat/libuiohook/blob/dbab471930671ebeb6c9a09f41531afef0405e45/src/x11/post_event.c#L126

Interesting fact, if I pass the NATIVE_MOUSE_MOVED or NATIVE_MOUSE_DRAGGED as an id, it works almost fine untill I start moving the cursor

kwhat commented 2 years ago

I just did a ton of work on the event posting for all three supported platforms but mouse wheel events have not been tested yet. Please check the latest snapshot and let me know if this is still an issue.

Chae4ek commented 2 years ago

Hi, @kwhat! Thank you for supporting this project so far) Unfortunately, the problem is still here

kwhat commented 2 years ago

Should be fix in the latest update.

kwhat commented 2 years ago

Please reopen if it is still not working.

Chae4ek commented 2 years ago

That works now, but I noticed the behavior had changed a bit. For example:

NativeMouseWheelEvent event =
    new NativeMouseWheelEvent(
        NativeMouseEvent.NATIVE_MOUSE_WHEEL,
        NativeMouseEvent.BUTTON5_MASK,
        300,
        250,
        1,
        NativeMouseWheelEvent.WHEEL_UNIT_SCROLL,
        1,
        1,
        NativeMouseWheelEvent.WHEEL_VERTICAL_DIRECTION);
GlobalScreen.postNativeEvent(event);

I expect (should it work so?):

  1. the cursor is set to (300,250)
  2. the mouse wheel is scrolled up
  3. the cursor is set to its original position

I tested it on Windows: it seems only the 2nd point is done. on Linux: 1 and 2. It looks weird when I move the mouse too fast and post an event, even if I do it in the nativeMouseMoved method cause of the delay.

P.S. I cannot reopen the issue

kwhat commented 2 years ago

The library won't be able to compensate for mouse movement while sending events. If you move the mouse while events are being sent, both will happen at the same time. I am not sure how this works on Windows or OS X. We might be able lock the mouse input on Linux while events are being sent, but I am not sure if that will effect the events being posted.

  1. should be done on Linux because I need to manually move the mouse.
  2. should be done on all platforms.
  3. is not currently done on Linux, but could be fairly easily.

I am not sure how 1 & 3 behave on Windows or OS X. 2 should work on both but hasn't been tested extensively.

Chae4ek commented 2 years ago

Well, I've experimented a bit and figured out that without moving the cursor (just comment this out) this event works the same way as on Windows. It also works fine when moving the mouse quickly.

kwhat commented 2 years ago

Well, I've experimented a bit and figured out that without moving the cursor (just comment this out) this event works the same way as on Windows. It also works fine when moving the mouse quickly.

Interesting, those lines seem to be required for Button Press/Release events to behave similarly to Windows. Can you check the button press/release stuff and let me know? I don't think I'll have to to check this today but tomorrow should be good.

Chae4ek commented 2 years ago
  1. setting the cursor to position
  2. pressing/releasing/scrolling at the current position
  3. setting the cursor to its original position

Hmm.. button press/release behaves like 1&2 above on linux, but on Windows like just 2. I think it's a question about new features to do 1&2(&3 probably?) and only 2 to reduce or get rid of the delay. btw I need to perform only the 2nd one, I can't do it with the current lib functions.

Since those lines are in a different method (post_mouse_wheel_event instead of post_mouse_button_event), they don't affect pressing/releasing button.

kwhat commented 2 years ago

Well, I've experimented a bit and figured out that without moving the cursor (just comment this out) this event works the same way as on Windows. It also works fine when moving the mouse quickly.

Alright I am adding this change so that should hopeful make things usable.

kwhat commented 2 years ago

Let me know if there are still issues, I can reopen.