Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Touchpad scroll on some Windows laptops

Discussion in 'Editor & General Support' started by MythicalCity, Apr 15, 2018.

  1. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    418
    Hi, I'm using Input.GetAxis("Mouse ScrollWheel") to get scrollwheel input, this works with all mice, on Macs but some windows laptops don't return anything when trying to scroll on the touchpad. Works fine in the editor (I can use 2 fingers to scroll) but this code or Input.mouseScrollDelta doesn't return anything. One of the laptops is a Razer Blader 14".
     
  2. bkachmar

    bkachmar

    Joined:
    Mar 15, 2013
    Posts:
    41
    Hi.
    I am also looking for the answer to this issue.
    Microsoft Surface touchpad scroll works, but Xiaomi laptop and a few years old Sony Vaio don't.
    @capitalJmedia did you solve this already?
     
  3. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    418
    No I haven't figured it out, we can't get the scroll to work on a Razer Blade laptop either.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I believe this entirely depends on touchpad driver support.
     
  5. Baschti-aus-s

    Baschti-aus-s

    Joined:
    Jan 6, 2020
    Posts:
    9
    Sorry for exhuming this pretty old thread, but i am facing the exact same problem as the TO. I have searched for hours now and the only solution i found is using the OnGui() methode and then a combination of EventType.ScrollWheel and Event.delta (see: https://answers.unity.com/questions/725166/get-scroll-wheel-axes-from-windows-trackpad.html)

    I don't have try this until now, because in my opinion, Input.GetAxis("Mouse ScrollWheel") or something similar has to work too and I only miss something. In addition to this, it feels like a pain in the ass to use the OnGui() methode because its calles several times in one frame on every interaction in the game. A check in update() is quiete enough for my use case.

    Scrolling in every other application on Windows even in the Unity editor itself works by using two fingers on the touchpad. So i guess there has to be some input value available in the game as well by using this gesture on the touchpad. The question where can i find it? Do i have to define some additional input axis for this?

    Did anybody has any helpful new input here?

    One additional question: Why in hell does the touch gesture is a ScrollWheel event for OnGui() but is not interpreted as mouse wheel scroll by Input.GetAxis("Mouse ScrollWheel") and how can this only depend on the driver of the touchpad? I guess anywhere in the Unity universe an information is available which tells, that the touchpad was used instead of the physical mouse wheel.

    Thanks for any help!
     
  6. Baschti-aus-s

    Baschti-aus-s

    Joined:
    Jan 6, 2020
    Posts:
    9
    I have digged a little bit arround this problem and found the used methodes of the Event and the Input class, which are used to get the scroll information.

    Event:
    Code (CSharp):
    1. [MethodImpl(MethodImplOptions.InternalCall)]
    2. private extern void get_delta_Injected(out Vector2 ret);
    Input:
    Code (CSharp):
    1. [MethodImpl(MethodImplOptions.InternalCall)]
    2. private static extern void get_mouseScrollDelta_Injected(out Vector2 ret);

    I have tryed to use them in my own class, but I got an access exeption when I try to call one of them. So I investigate this a little bit more and find the following, interesting site:
    https://www.mono-project.com/docs/advanced/embedding/

    When i understand this right, i have to "register" my own class using
    Code (CSharp):
    1. mono_add_internal_call ("MyClass::get_delta_Injected", get_delta_Injected);
    in the Unity C/C++ code, which i am not able to do ^^

    And then it should be possible to use
    Code (CSharp):
    1. class MyClass {
    2.   [MethodImpl(MethodImplOptions.InternalCall)]
    3.   private static extern void get_delta_Injected(out Vector2 ret);
    4. }
    So it seems to be a deadlock. If someone has any further ideas, I am definitively interested in it ;)
    For now, there was no other option than using the OnGui() methode additionally. I adapted the solution which is mentioned in my earlier post, so here is the complete implementation, if someone is interessted (code is reduced to the relevant segements):

    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3.  
    4. public class CameraMovement : MonoBehaviour
    5. {
    6. #pragma warning disable 0649
    7.     [SerializeField]
    8.     private GameObject GO_MainCamera;                        
    9. #pragma warning restore 0649
    10.  
    11.     private float mouseScrollDelta = 0f;                              
    12.  
    13.     // Only used for processing laptop touchpad scroll
    14.     public void OnGUI()
    15.     {
    16.         // Input.mouseScrollDelta.y stays at 0 if laptop touchpad was used to scroll
    17.         if(Event.current.isScrollWheel && Input.mouseScrollDelta.y == 0)  
    18.         {
    19.             if (Event.current.delta.y > 0)
    20.             {
    21.                 mouseScrollDelta = 1f;
    22.                 Zoom("Mouse");
    23.             }
    24.             else
    25.             {
    26.                 mouseScrollDelta = -1f;
    27.                 Zoom("Mouse");
    28.             }
    29.         }
    30.         else { }
    31.     }
    32.  
    33.     public void Update()
    34.     {
    35.         // Scroll with physical mouse wheel
    36.         if (Input.mouseScrollDelta.y != 0)
    37.         {
    38.             mouseScrollDelta = Input.mouseScrollDelta.y;
    39.             Zoom("Mouse");
    40.         }
    41.  
    42.     }
    43.  
    44.     /// <summary>
    45.     /// Camera zoom depending on mouse (wheel) or touch (pinch) input
    46.     /// </summary>
    47.     /// <param name="inputType"></param>
    48.     private void Zoom(string inputType)
    49.     {
    50.         currentPositionCamera = GO_MainCamera.transform.position;
    51.         float zoomOffset = 0f;                                                
    52.         Vector3 newCameraPosition;
    53.      
    54.         if (inputType == "Mouse")
    55.         {
    56.             zoomOffset = mouseScrollDelta * 1f; // Global settings variable replaced by 1f                                                        
    57.         }
    58.         else if (inputType == "Touch")
    59.         {
    60.             // Method when touch display is used
    61.         }
    62.         else { }
    63.  
    64.         Vector3 zoomMovement = new Vector3(0f, -zoomOffset, zoomOffset);      
    65.         newCameraPosition = currentPositionCamera + zoomMovement;            
    66.         GO_MainCamera.transform.position = newCameraPosition;
    67.     }
    68.  
    69. }