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

Input.GetKey Shift Key disbles GetAxis Mouse ScrollWheel?

Discussion in 'Editor & General Support' started by Gordon_G, Mar 7, 2020.

  1. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    I have this code, and as soon as I press the shift key the scroll wheel input is not registered. (neither method A or B works) Any other KeyCode doesn't cause this problem. (Unity 2019.2.11/f1)

    What gives?

    Code (CSharp):
    1. // method A  ***********
    2. if( Input.GetKey( KeyCode.LeftShift ) ) {
    3.    Debug.Log( "ShiftKey pressed" );
    4. }
    5.  
    6. float scroll = Input.GetAxis( "Mouse ScrollWheel" );
    7. if( scroll > 0.001f ) {
    8.    Debug.Log( "Scrolling = " + scroll );
    9.    // no output if shift down
    10. }
    11. //***********
    12.  
    13. // method B ***********
    14. float scroll = Input.GetAxis( "Mouse ScrollWheel" );
    15. if( scroll > 0.001f ) {
    16.    Debug.Log( "Scrolling = " + scroll );
    17.    if( Input.GetKey( KeyCode.LeftShift ) ) {
    18.       Debug.Log( "ShiftKey pressed" );
    19.    }
    20.    // no output if shift down from either Log
    21. }
    22. //***********
     
    Last edited: Mar 7, 2020
  2. Ted-Brown

    Ted-Brown

    Joined:
    Oct 16, 2012
    Posts:
    32
    I just ran into this problem as well. It appears to be a bug that is highly specific to the hardware!

    I'm running 2019.3 on Mac OS 10.14.6 on a MacBook Pro.

    If I hold shift on an external keyboard or the laptop keyboard:
    • I can't scroll with my external mouse
    • but I can scroll with the touchpad!!!
    This same code works on Windows desktops without a problem.

    What's your setup?
     
  3. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    HUH... well that might explain something then! I've got Unity 2019.2 and I'm on a Macbook pro running 10.12.6.

    so that would be really weird. I'm not that worried about it, but I figured there must be an answer there somewhere. Thanks!
     
  4. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    40
    Huh, have the same issue.
    I'm running Unity 2020.1 with the New Input System on MacOS 10.14.6.

    Have you guys figured it out?
     
  5. romanpapush

    romanpapush

    Joined:
    Sep 20, 2012
    Posts:
    40
    Ok, it's just the way MacOS handles mouse scroll wheel.
    While Shift is held down it emulates horizontal scroll. So just use scroll.x and you'll be fine.
     
  6. dd_creative

    dd_creative

    Joined:
    Nov 4, 2020
    Posts:
    1
    Yes, I was in the same situation(2019.3.12, MacOS 10.14.6)
    thanks romanpapush your answer saved me :)

    I solved it by returning the one with bigger abs value.

    Code (CSharp):
    1. void OnGUI() {
    2.         Vector3 pos = transform.position;
    3.         if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) {
    4.             // https://forum.unity.com/threads/input-getkey-shift-key-disbles-getaxis-mouse-scrollwheel.842062/
    5.             pos.x += getSignificantValue(Input.mouseScrollDelta) * scale;  
    6.             print(pos);
    7.         } else {
    8.             pos.z += Input.mouseScrollDelta.y * scale;
    9.         }
    10.         transform.position = pos;
    11.     }
    12.  
    13.     private float getSignificantValue(Vector2 input) {
    14.         if (Mathf.Abs(input.x) > Mathf.Abs(input.y)) {
    15.             return input.x;
    16.         }
    17.         return input.y;
    18.     }
     
    Gordon_G likes this.
  7. Xerisis

    Xerisis

    Joined:
    Feb 19, 2016
    Posts:
    2
    Just for a reference for the new Input System If you add a binding for both Scroll/Y and Scroll/X you will be good to go.

    Note: Scroll X seems to be inverted...
     
    MatanYamin likes this.