问题
I am looking for a method to reliably distinguish within [NSResponder scrollWheel:]
if the users input device has a one-dimensional scroll-wheel or a two dimensional trackPad/magicMouse?
In the first I would like to implement a different behavior.
But just taking a look on the deltaX of the NSEvent
would be a little weak.
Any suggestions?
回答1:
You can use the private method call [theEvent _scrollPhase]
to tell whether the device is using inertial scrolling, which indicates an Apple-supplied input device. (Note: this won't work if the user has disabled inertial scrolling)
回答2:
Use the event's subtype:
enum {
NSMouseEventSubtype = NX_SUBTYPE_DEFAULT,
NSTabletPointEventSubtype = NX_SUBTYPE_TABLET_POINT,
NSTabletProximityEventSubtype = NX_SUBTYPE_TABLET_PROXIMITY
NSTouchEventSubtype = NX_SUBTYPE_MOUSE_TOUCH
};
This will work even with inertial scrolling disabled.
来源:https://stackoverflow.com/questions/5217680/cocoa-distinguish-input-device-scrollwheel-as-mouse-scroll-wheel-and-trackpa