MacOS Incorrect GCMouse being used when mouse button is held and moved

108 Views Asked by At

I am trying to emulate multiple mouse cursors on MacOS using raw mouse input. It all works fine until a mouse button is held and the mouse is then moved. While the mouse button is being held the incorrect GCMouse device is being used on the mouseMovedHandler. It seems as though it is capturing the mouse and functioning as dragging.

This is the code fragment being used:

-(void) registerMouseCallbacks:(GCMouse*) mouse withGid:(int)mid {  
    __block int gid = mid;
    
    mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouseinp, float deltaX, float deltaY) {
        /* gid is correct here until a mouse button is held down and moved, then gid appears to be the last connected mouse */
        /* I have also tried printing out NSLog([mouseinp.device vendorName]) and verified its incorrectly using the wrong mouse device. */
        handle_mousemove(gid, deltaX, -deltaY);
    };
    
    mouse.mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
        handle_mousepress(gid, pressed);
    };
 }
 
 [[NSNotificationCenter defaultCenter] addObserverForName:GCMouseDidConnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
    GCMouse* mouse = note.object;

   int idx = genIdx(); // unique id per connection

    // Register for mouse events
    [self registerMouseCallbacks:mouse withGid:idx];
}];
0

There are 0 best solutions below