Search Unity

Can i script for the 2 side mouse buttons

Discussion in 'Scripting' started by melonhead, Jun 17, 2019.

  1. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    I need to buy a new mouse and want to know if i can use the 2 extra buttons on the side of the mouse probably buttons 3 and 4, as i do not have these buttons at the moment i have no way of testing if i can code for these, i think the buttons are used for forward and backwards pages when using the internet but can i use something like
    (Input.GetMouseButtonDown(3)) and (Input.GetMouseButtonDown(4))

    i have had a search but can only find some old posts from a few years back saying they can not be used, but have these now been implemented in unity, as i would be pretty suprised if not seeing as most gaming mice will have these button

    cheers
     
  2. WallaceT_MFM

    WallaceT_MFM

    Joined:
    Sep 25, 2017
    Posts:
    394
    You could use virtual buttons with the InputManager.
    Code (csharp):
    1. // Instead of this
    2. //Input.GetMouseButtonDown(3)
    3. // Use this
    4. Input.GetButtonDown("Fire3")
    You could then change the binding for Fire3 to your mouse buttons. For testing, you could bind to Q or some other key, and then change it to mouse2 when you get your new mouse.
     
  3. EdGunther

    EdGunther

    Joined:
    Jun 25, 2018
    Posts:
    183
    There has to be some Unity recognized input.

    The input manager may help (Edit -> Project Settings -> Input) but not if you don't know what the input is called.

    Try this in your update function
    Code (CSharp):
    1. for (int i = 0; i < 7; i++)
    2.         {
    3.             if (Input.GetMouseButtonDown(i))
    4.                 Debug.Log(i);
    5.         }
    and click away!! see what happens lmao




    EDIT: I just tested this in my game and I don't get any console errors as long as I set i<7. That means there are definitely more recognized mouse inputs than 0, 1, & 2.
     
    SparrowGS likes this.
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
  5. danielmanzie87

    danielmanzie87

    Joined:
    Dec 4, 2020
    Posts:
    5
    Thanks. I looked through the document and found what I was looking for. I used "Mouse3" to get my mouse side button to work. I wrote the code like this:

    if (Input.GetKey(KeyCode.Mouse3))
    {
    //Do something.
    }
     
  6. spiritwolf_u3d

    spiritwolf_u3d

    Joined:
    Jul 11, 2022
    Posts:
    1
    unity new input system support for mice with more than 5 buttons ?
    The old input system had support for mice with up to 7 buttons; KeyCode went from Mouse0 to Mouse6. The new input system, however, has

    leftButton rightButton middleButton forwardButton backButton Only 5 buttons. Can we get support for many-buttoned mice like this one?https://www.corsair.com/us/en/Categ...Play-Mice/scimitar-pro-config/p/CH-9304011-NA