- Home /
Horizontal Scrolling on a Trackpad (MacOS X)
I need to be able to detect horizontal scrolling on trackpads on MacOS. Input.getAxis("Mouse ScrollWheel")
detects the vertical axis, but there's nothing built in (that I'm aware of) for the horizontal axis.
I created a plugin that attached an NSResponder to the main window and listened to some trackpad events. swipeWithEvent
is the one I care most about, but I also detected magnifyWithEvent
and rotateWithEvent
for the fun of it. I attached it with this code: [[[NSApplication sharedApplication] mainWindow] setNextResponder:obj]
That worked, but only for the magnify and rotate events. It still can't detect the swipes. I think the problem is that my object is lower on the responder chain and Unity needs to listen to swipeWithEvent for the "Mouse ScrollWheel" axis. So I tried this code after the previous line: [[[NSApplication sharedApplication] mainWindow] makeFirstResponder:obj]
That didn't change anything. Unity still gets swipes first, and it's tossing out the horizontal axis scrolling as far as I know.
Is there anything I can do? I'd be perfectly okay with a solution where my plugin ends up taking over both axes and I have to rewrite the code that uses Input.getAxis("Mouse ScrollWheel")
Answer by sarysa · Jun 22, 2012 at 09:44 PM
Self-answer. Doesn't look like there's a way to just poll it at any time. All calls to OnGUI() need to be checked and code like this needs to be implemented:
Event ev = Event.current;
if (ev.type == EventType.ScrollWheel)
{
someX = ev.delta.x;
someY = ev.delta.y;
}
Answer by greay · Mar 31, 2018 at 12:54 AM
This is ages late, but it's worth pointing out at least with Unity 5.6.4, it's possible to get it from Input.mouseScrollDelta – which looks to work anywhere you'd use Input.GetAxis(). The scale is different, however: on initial glance, it's a flat 10x.