ARTICLE AD BOX
I am working on a remote control application for macOS where I need to maintain two "virtual" cursors:
Remote Cursor: Follows the remote user's movements.
Local Cursor: Follows the local user's physical mouse/trackpad movements.
To move the system cursor (for the remote side), I use CGWarpMouseCursorPosition as follows:
void DualCursorMac::UpdateSystemCursorPosition(int x, int y) { CGPoint point = CGPointMake(static_cast<CGFloat>(x), static_cast<CGFloat>(y)); // Warp the cursor to match remote coordinates CGWarpMouseCursorPosition(point); }Meanwhile, I use a CGEventTap to monitor local physical movements to update my local virtual cursor's UI:
CGEventRef Mouse::MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { if (remoteControlMode) { // We want to suppress system cursor movement but still read the delta const int deltaX = static_cast<int>(CGEventGetIntegerValueField(event, kCGMouseEventDeltaX)); const int deltaY = static_cast<int>(CGEventGetIntegerValueField(event, kCGMouseEventDeltaY)); NSLog(@"MouseTapCallback: delta:(%d, %d)", deltaX, deltaY); // Update local virtual cursor UI based on deltas... return nullptr; // Consume the event } return event; }The Problem:
When CGWarpMouseCursorPosition is called frequently to update the system cursor, it interferes with the kCGMouseEventDeltaX/Y values in the Event Tap.
Specifically, if the local user moves the trackpad slowly (expecting deltas of 1 or 2), but a "Warp" occurs simultaneously (e.g., jumping the cursor from (100, 100) to (300, 300)), the deltaX and deltaY in the callback suddenly spike to very large values. It seems the system calculates the delta based on the new warped position rather than the pure physical displacement of the trackpad.
This makes the local virtual cursor "jump" erratically and makes it impossible to track smooth local movement during remote control.
My Question:
Is there a way to get the "raw" or "pure" physical relative movement (delta) from the trackpad/mouse that is independent of the system cursor's absolute position or warping?
Are there alternative APIs (perhaps IOKit or different CGEvent fields) that would allow me to get consistent deltas even when the cursor is being warped programmatically?
