Limitation of using OnGUI for Touchpad "ScrollWheel"?

Thanks to a few suggestions I’ve found here I’m using OnGUI() to use the ScrollWheel Event to add a Camera Zoom effect. It works great, as long as I’m not doing anything else.

But if I’m using the keyboard to control my character (“WASD”), then the OnGUI Event is for the keyboard, and doesn’t pick up the MouseWheel event from the Touchpad.

Any suggestions on a workaround? I’ve looked at the Event.PopEvent but there’s almost no documentation on how it works or what to do with it, so I’m not sure if I’m just missing a workaround.

I don’t quite get your second paragraph. OnGUI does process many different events.which includes key, mouse and scrollwheel events. OnGUI is called for each event seperately.

Event.PopEvent shouldn’t be used manually as it will permanentally remove an event from the event queue which prevents any other script or system to process this event. It’s used by the new UI system internally to get the UI events.

What does your actual code look like?

As an alternative you should be able to use the virtual input axis named “Mouse ScrollWheel” in conjunction with Input.GetAxis. Even the axis is usually defined by default it’s possible that you or something else in your project has remove it from the Input manager. So if it doesn’t work, check the input manager (Edit → Project Settings → Input).

EDIT
Ok, the Mouse/Keyboard inputs seem to be a limitation on my laptop. I decided to test outside of Unity and pressing any keys on my keyboard essentially shuts off my Touchpad. There’s probably a setting somewhere in Windows or my Touchpad software that’s limiting me.

/EDIT

This code runs fine if I do not use any keys on my keyboard. But holding W to have my character run forward makes this stop.

If I’m not touching the keyboard, and “Scroll” with the Touchpad, and while still scrolling I press a keyboard key everything works as it should. The moment I stop touching the Touchpad means I can’t scroll until I stop using the keyboard.

And Input.GetAxis(“Mouse ScrollWheel”) does not work with touchpads, hence the use of OnGUI().

public void OnGUI()
    {
        if (Event.current.isScrollWheel)
            // do stuff with  Event.current.delta
            cameraController.CameraDolly(Event.current.delta.y / 100);
    }