I am trying to slow down the mouse cursor programmatically by multiplying the mouse delta by a number between 1 and 0 on every mouse move event. It’s working fine for the X axis, but the Y position always gets moved back to the center of the screen, it’s very bizarre.
I can’t seem to figure out why the Y position of the cursor gets moved towards the center of the screen no matter whether you move the mouse up up or down…
I set up a CGEventTap for mouse move events, and this is the code for the callback:
CGEventRef
mouse_filter(CGEventTapProxy proxy, CGEventType type, CGEventRef event, float *speed_modifier) {
CGPoint point = CGEventGetLocation(event);
NSPoint old_point = [NSEvent mouseLocation];
CGPoint target;
int tX = point.x;
int tY = point.y;
float oX = old_point.x;
float oY = old_point.y;
float dX = tX-oX;
float dY = tY-oY;
dX*=0.1, dY*=0.1;
tX = round(oX + dX);
tY = round(oY + dY);
target = CGPointMake(tX, tY);
CGWarpMouseCursorPosition(target);
return false;
}
Can someone help me figure out how to do this?
I logged some values during the running of the application and discovered that oY does not seem to contain the expected values… it seems to always be close to 430, usually within a couple pixels of that. tY contains the seemingly correct target value, so it stands to reason that oY from one iteration should be equal to tY from the previous one (it works properly for the X values), however, oY is always close to 430, even when the mouse should be moving towards the top of the screen. This makes me think that dY is somehow being set to a value that will bring oY back to around 430, but I can’t figure out how that is happening, as dY seems to output the correct value as well…
CGPoint point = CGEventGetLocation(event);is a point where (0,0) is the top left of the screen.
NSPoint old_point = [NSEvent mouseLocation];is a point where (0,1) is the bottom left of the screen.
I if I get the screen height, and do:
‘oY = abs(oY – screen_height+1);`, oY is now based off the top Left of the screen, and my application works properly.