Search Unity

Input.GetMouseButtonDown not working as expected when more than one mouse button is pressed

Discussion in 'Scripting' started by Nagezahn, May 28, 2017.

  1. Nagezahn

    Nagezahn

    Joined:
    Dec 11, 2015
    Posts:
    2
    Hi,

    I'm currently having an issue with Input.GetMouseButtonDown(). For example see the following code snippet:
    Code (csharp):
    1.     void Update() {
    2.         if (Input.GetMouseButtonDown(0)) {
    3.             Debug.Log(Time.frameCount.ToString() + ": Left Mouse Button Down");
    4.         }
    5.         if (Input.GetMouseButtonDown(1)) {
    6.             Debug.Log(Time.frameCount.ToString() + ": Right Mouse Button Down");
    7.         }
    8.     }
    When I press the left or the right mouse button, the code works like I expect and prints a message on the debug console. Likewise if I press for example the left button, then the right button without releasing the left one, two appropriate messages are printed. However, when I press both the left and the right mouse button at the same time (i.e. during one frame), no message is printed at all. More so, when pressing both buttons, then releasing and pressing one of them while the other one is still pressed, no messages are printed. I have to release both buttons to see messages again in the console.

    A little more info: I'm running on Arch Linux (x64) and an EventSystem is part of my Scene. Although disabling the latter doesn't change anything.

    I don't think this is intended behaviour. Maybe I am doing something wrong? If anyone has any hints for me in this regard I'd be grateful.
     
  2. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Code looks fine and I'd think unity would allow this.. but I wonder if your mouse (or OS / Drivers) itself has ability to register both left and right mouse clicks at same time... Is there some sort of app (non unity) you can test this in?


    Edit: Just so you know, I tested this with my mouse/PC and it works like you'd intend

    Edit2: I'd probably steer away from requiring the user to hit both buttons at the exact same time for this reason.. not all mice (or drivers or OS, or whatever the limitation is) can register both down at the exact same time, apparently.. if you can avoid that.
     
    Last edited: May 28, 2017
  3. Nagezahn

    Nagezahn

    Joined:
    Dec 11, 2015
    Posts:
    2
    Thank you very much for your input! Just as a side note: I don't require the user to press both buttons at the same time, but one should be able to press both to execute the respective commands in parallel.

    It didn't occur to me to actually check my system/mouse in this case. Turns out the mouse hat a "Middle Emulation" enabled. There is some info on this topic in an SO question: https://unix.stackexchange.com/a/9992

    I checked for my device's number by running
    Code (csharp):
    1. xinput list
    which led me to the id 9. Next I did a query for this devices properties by running
    Code (csharp):
    1. xinput list-props 9
    which listed
    Code (csharp):
    1. libinput Middle Emulation Enabled (289):    1
    . So I ran
    Code (csharp):
    1. xinput set-prop 9 289 0
    and the script I posted then produced the desired log output.

    Now I only have to find a way to turn this off by default. Most likely by adding an evdev rule, will try this out.