Scroll with Laptop Touchpad Using 2 Finger Swipe

I am trying to implement camera zoom using the touchpad on my laptop. Input.mouseScrollDelta.y only seems to work with a physical mouse.

I read that touchpad events can be handled with private void OnGUI() which will be called for rendering and handling GUI events (although I’m not sure why a touchpad scroll is classified as a GUI event?).

I tried a few things but I can’t get my script to recognize the two finger swipe on my touchpad as input. Does the new input system have an easy way to handle this as opposed to the legacy system?

Any tips on how to solve this issue would be appreciated!

    private void OnGUI()
    {
        float zoomAmount = 1f;
        if (Event.current.type == EventType.ScrollWheel)
        {
            if (Event.current.delta.y > 0)
            {
                targetFollowOffset.y -= zoomAmount;
            }

            if (Event.current.delta.y < 0)
            {
                targetFollowOffset.y += zoomAmount;
            }
        }
        targetFollowOffset.y = Mathf.Clamp(targetFollowOffset.y, MIN_FOLLOW_Y_OFFSET, MAX_FOLLOW_Y_OFFSET);
        float zoomSpeed = 5f;
        cinemachineTransposer.m_FollowOffset = Vector3.Lerp(cinemachineTransposer.m_FollowOffset, targetFollowOffset, Time.deltaTime * zoomSpeed);
    }

Out of the box, there is no true solution for this. There was a clever programmer who had an asset in the asset store for native interactions with a trackpad, but that’s long since been deprecated (and it was for the old input system).

I did find something here: but that’s for OSX only,

Privacy & Terms