Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get Mouse Scroll from Touchpad?

Input.mouseScrollDelta only changes for a physical mouse scroll wheel. It is not changing for a touch-pad two-finger scroll gesture (though the scroll icon does appear and otherwise works in other programs). Input.GetAxis("Mouse ScrollWheel") has the same effect. Input.touchCount (or anything touch related) is only for touch screens and doesn't help me make my own scroll check on a touch pad. So I'm out of ideas. How in the world am I supposed to know I'm scrolling on a laptop's touch pad?

like image 342
CodeMonkey Avatar asked Oct 16 '25 15:10

CodeMonkey


1 Answers

Since you've tagged it Unity3d, maybe this will help you overcome: https://answers.unity.com/questions/356767/how-to-get-scrollwheel-values-using-a-laptop-touch.html

public void OnGUI()
 {
     if(Event.current.type == EventType.ScrollWheel)
         // do stuff with  Event.current.delta
         Debug.Log(Event.current.delta);
 }

The OnGui documentation can be found here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button"))
        {
            print("You clicked the button!");
        }
    }
}

OnGUI is called for rendering and handling GUI events.

This means that your OnGUI implementation might be called several times per frame (one call per event). For more information on GUI events see the Event reference. If the MonoBehaviour's enabled property is set to false, OnGUI() will not be called.

like image 119
Athanasios Kataras Avatar answered Oct 19 '25 05:10

Athanasios Kataras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!