libuiohook icon indicating copy to clipboard operation
libuiohook copied to clipboard

Windows Fix Multiple Monitor Mouse Input

Open FaithBeam opened this issue 2 years ago • 5 comments

Hello! This PR fixes libuiohook's issue with multi-monitor mouse input and movement for Windows.

Very quickly, this is done by converting the low-level mouse hook coordinates that libuiohook returns to be relative to the virtual desktop. It creates an invisible window and listens for the WM_DISPLAYCHANGE event which is sent whenever a monitor changes position or resolution to get the width and height of monitors in relation to the primary monitor. I wrote some notes and examples here if you want to take a look: https://i.imgur.com/z3vKjtm.png

This video shows a modified demo_hook/post_async with the change. This change does not touch dpi stuff, so the calling application should set something like SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); to handle monitors that are not 100% scale. https://youtu.be/YhrC_oLPtRM

The modified program listens for middle mouse button release and sends a right mouse button down and up at the current mouse coordinates.

This is the sample program: https://gist.github.com/FaithBeam/e90bad32fd2fef0c825cfa9c403f9e7b

Should fix #21.

FaithBeam avatar Feb 19 '23 16:02 FaithBeam

@FaithBeam this pull request is a little out of date - could you please rebase it on top of the 1.3 branch and resolve conflicts? Also, the original pull request contained a couple more commits - could you add them here as well?

@kwhat did you have a chance to review this pull request?

TolikPylypchuk avatar Jun 27 '23 19:06 TolikPylypchuk

@TolikPylypchuk if @kwhat expresses interest in this, I'll update the PR.

FaithBeam avatar Jun 27 '23 20:06 FaithBeam

Ive looked at this vut i still dont understand why its needed.

kwhat avatar Jun 27 '23 21:06 kwhat

It's been a while since I last looked at the code, but libuiohook doesn't calculate the correct coordinates for mouse input when multiple monitors are connected on Windows.

One monitor: works Multiple monitors: broken

This PR fixes multiple monitor mouse input for Windows.

FaithBeam avatar Jun 28 '23 10:06 FaithBeam

Sorry, I accidentally closed this. Reopening.

FaithBeam avatar Jun 28 '23 10:06 FaithBeam