Detecting CGAssociateMouseAndMouseCursorPosition

MacosCore GraphicsMouseeventQuartz Graphics

Macos Problem Overview


We're making a user-space device driver for OS X that moves the cursor using Quartz Events, and we ran into a problem when games — especially ones that run in a windowed mode — can't properly capture the mouse pointer (= contain/keep it within the boundaries of their windows). For example, it would go outside the game window and click on the desktop or nearby inactive applications.

We could fix this if only we could detect when an active application calls CGAssociateMouseAndMouseCursorPosition.

How would you do this? Any ideas are appreciated.

Macos Solutions


Solution 1 - Macos

I dont know if this can help you

There is an option called Focus Follows Mouse

Focus Follows Mouse - The Mouse pointer will grab automatically change focus to a new window inisde this one app if you mouse over it, instead of having to click a window to get focus, then clicking to do something.

http://wineskin.urgesoftware.com/tiki-index.php?page=Manual+4.6+Advanced+-+Options

Solution 2 - Macos

I have written a few different mouse logical layers (for bridging different input devices, etc.). I have found that hooking into the OS level WM_INPUT event is a sure way of getting very real-time mouse position information. There is also a less rigorous solution of just polling the mouse data you need from one of Windows' very primitive DLLs. They are lightning fast. You could poll on a 10ms timer and never see performance loss on a modern machine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaeView Question on Stackoverflow
Solution 1 - MacosMauricio Gracia GutierrezView Answer on Stackoverflow
Solution 2 - MacosDanielView Answer on Stackoverflow