I would like to get mouse movements with high resolution and high frame rate on OSX.
"High frame rate" = 60 frames per second or higher (preferably> 120)
"High resolution" = sub-pixel values
Problem
I have an opengl view that runs at the monitor refresh rate, so it is ~ 60 frames per second. I use the mouse to look around, so I hid the mouse cursor and I rely on the delta values of the mouse.
The problem is that mouse events occur at too low frame rates, and the values are snapped to integers (whole pixels). This causes an intermittent scan. Here's a visualization of mouse delta values over time:
mouse delta X
^ xx
2 | x x x x xx
| x x x x xx x x x
0 |x-x-x--xx-x-x-xx--x-x----x-xx-x-----> frame
|
-2 |
v
() , , . x deltaX , deltaX , . , deltaX 0,000 , 1.000 , 0.000, 2.000, 0.000 , 3.000, 0.000 ..
, 2.000 , 0,000 , 3.000 . , . , .
, 1) ? 2) ?
:
- (void)mouseMoved:(NSEvent *)theEvent {
CGFloat dx, dy;
dx = [theEvent deltaX];
dy = [theEvent deltaY];
actOnMouse(dx,dy);
}
, . dx float, (0.000, 1.000 ..). .
, , WindowServer, . , CGEventTrap:
eventMask = (1 << kCGEventMouseMoved);
eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap,
0, eventMask, myCGEventCallback, NULL);
myCGEventCallback(...){
double dx = CGEventGetDoubleValueField(event, kCGMouseEventDeltaX);
double dy = CGEventGetDoubleValueField(event, kCGMouseEventDeltaY);
}
n.000, , . 60 . .
, . , OSX - -, - "" , , , - .
, , IOKit. . . Apple , , : " , , , ".
, . .
<IOKit/hidsystem/IOLLEvent.h> 377 :
struct {
UInt8 subx;
UInt8 suby;
} mouse;
, ! . 73 <IOKit/hidsystem/IOLLParameter.h>
#define kIOHIDPointerResolutionKey "HIDPointerResolution"
.
, , OSX , , , .
Erh, , ?
- OSX? ( ?)
- OSX? ( ?)
- "" ? (.. .)
- , NXEvents HIDParameters? ? ( ...)
( )