Cocoa: distinguish input device / scrollWheel: as mouse-scroll wheel and TrackPad

我是研究僧i 提交于 2020-01-05 04:31:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!