kwhat / jnativehook

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

RFE: relative mouse movement listener. #198

Open martin-mucha opened 7 years ago

martin-mucha commented 7 years ago

Hi,

I'm not blocked by this at all, and I'm even able to overcome this if it ever become limitation for my usecase, but I think it might be extremely usefull to also be able to listen to 'relative' mouse movement, relative to last location. To explain: currently we can get absolute position of mouse on screen. But movement to left will stop immediately when we reach screen boundary. IIRC hundreds of years back when I was playing with direct-x I was able to get information like x-10y+50, and calculate my own cursor location.

(not related to rfe: btw. this is briliant tool, which indeed should have been part of JDK from awt introduction. I did not donate yet, but I will, that's for sure.)

benjaminaigner commented 7 years ago

+1,

from my point of view it is impossible to calculate the relative movement if you block the mouse cursor (I know, not support, but in our case REALLY useful).

Does anybody have an idea for a workaround to get the relative mouse movement if the mouse events are consumed?

martin-mucha commented 7 years ago

to benjaminaigner: in my case, I actually have to hide mouse cursor anyway, so theoretically what I can do myself, is to manipulate actual mouse cursor into middle of the screen(because it's invisible, so nobody will notice) and calculate relative movement. That way, I can go indefinitely to the left. Indeed, that's very ugly hack. Because I don't like it, I'd rather have access to proper relative events, which could be possible, but most probably cannot be derived from absolute cursor position reported by windows.

kwhat commented 7 years ago

@benjaminaigner What do you mean "if you block the mouse cursor?" There is a way to calculate relative mouse movement using the screen objects in 2.1, but there is no way to automatically return relative movement. As far as movement beyond the boundary of a screen, I seem to remember events being delivered, but coordinates being pegged to the boundary. The actual mouse position for the library is returned by the OS, so much of that behavior would be dependent on how the OS handles screen boundaries.

Going back to the NativeMonitorInfo functionality, is there any reason that you cannot use a dispacher to track where the mouse is in conjunction with the screen information and adjust the evenets coordinates accordingly? That should solve most of the issue, but the screen boundary movement will still be a little tricky but maybe trackable by some vector direction of the events. Let me know if this sounds like a possible solution. If we come up with something that works, we can add to the growing list of provided dispatchers.