New Input System - Mouse Double Click

I’ve been using the new input system for my latest project and was wondering if there was a simple way to detect double clicks with the mouse.

I thought it was basically just adding a “multi tap” “interaction” to the “Action” but that does not seem to trigger the action.

I can obviously work around this by hard coding some timer or something but I thought there must be an easier more intuitive way in the new input system, especially since there’s a thing called multi tap.

public class MouseSelect : MonoBehaviour
{
    private InputActions inputActions;

  
    void Awake()
    {
        inputActions = new InputActions();
    }

    void OnEnable()
    {
        inputActions.Enable();
    }

    void OnDisable()
    {
        inputActions.Disable();
    }

    void Start()
    {
        inputActions.Controls.Fire.performed += _ => Select();
        inputActions.Controls.DoubleClick.performed += _ => FocusSelect();
        inputActions.Controls.AltFire.performed += _ =>  Deselect();
    }

    private void Select()
    {
        Debug.Log("Select");
    }

    private void FocusSelect()
    {
        Debug.Log("Focus select");
    }

    private void Deselect()
    {
        Debug.Log("Deselect");
    }
}
3 Likes

Bump

Im currently having the same Problem. I thought you would add 2 Interactions:
1.) Multitap
2.) Tap or Press

But the Multitap just eats the Input and Tap or Press are never performend.
The other way around Multitap never gets performed, wich is the correct Behaviour as far as i understand it.

Edit:
It works somewhat in this configuration:
1.)Press (press-only)
2.)Multitap

But this will give you an unwanted Press Interaction with every multitap
If you also want a hold interaction all hope is lost as it seems. I cant find a way to make it work.

If there is not a way to do this in the new input system I would appreciate if someone could flat out tell me/us, “no you have to create a script to time the pause in-between clicks to determine whether it’s a double click”.
Thanks!

@Hallur90 Maybe if you mark the Thread as “Help wanted” or “bug” ?

1 Like

MultiTap on leftButton would be expected to work (i.e. the setup as shown in the first screenshot). If it doesn’t as of 1.1-preview.2, would appreciate a ticket with the Unity bug reporter (“Help >> Report a Bug…” in the editor’s main menu) to ensure this gets looked at. IIRC there’s a test that sets up exactly this behavior, though, so wondering if something else is up here.

@Rene-Damm The Problem is, that the Setup in the Screenshot still requires you to discern if a Mouseclick is part of a double click. With this setup the single click action is performed 2 times during every double click.
The wanted setup would look like this: (But the multitap Interaction just swallows the Input, Single Tap never occurs)

Same here, in 1.1.0-perview 2. In multitap, the first click triggers the event, although it is true that the second click doesn’t, it gets ignored. The event is also triggered with only one click

I am not sure if this is expected, because in my opinion, the expected behavior should be that the first click is ignored and the event is triggered at the second click

I wrote a test about this. @Rene-Damm if you think this not the desired behaviour, I will report the bug

        [UnityTest]
        public IEnumerator DoubleClickTest()
        {
            InputAction doubleClickAction = new InputAction("Double Click");
            doubleClickAction.AddBinding("<Mouse>/leftButton", "Multitap");
            doubleClickAction.Enable();
            int doubleClickCounter = 0;
            doubleClickAction.started += (ctx) => doubleClickCounter++;


            var mouse = InputSystem.AddDevice<Mouse>();
            InputTestFixture inputTestFixture = new InputTestFixture();

            inputTestFixture.PressAndRelease(mouse.leftButton);
            yield return new WaitForSeconds(0.1f);

            // Fail. With only 1 click, the event shouldn't be triggered and the counter should be = 0
            Assert.AreEqual(0, doubleClickCounter);

            inputTestFixture.PressAndRelease(mouse.leftButton);
            yield return new WaitForSeconds(0.1f);

          // Pass. It has been 2 clicks and only 1 event, so this is ok
            Assert.AreEqual(doubleClickCounter, 1);
        }
2 Likes

Can confirm this bug, mine only works I set the tap count to 1, and can of course, tap once to trigger something. otherwise, double-tap and above won’t work.
tested on 1.1.0-preview.2

@LezTusi strange. They claim its fixed in that version: Unity Issue Tracker - Multi-tap and tap interactions in the same Action doesn&#39;t work properly

@LezTusi looks fixed to me. You can see in the log how the multitap gets cancelled and the tap is started instead:

1 Like

Using Unity 2020.1.17f1 with InputSystem 1.1.0-preview2 and it is not working for me. I’ve this move action setup, which is called two times if I perform a double click. I also tried to change the interaction order of tab and multi-tap, but this results in same behaviour.

Action binding is performed via script, while I also figured out that the PlayerInput component is buggy. If I use the PlayerInput component, the callback method is called 3 times (I think one for each state (down, press, up)), also without double-click behavior.

Can anyone confirm this?

BTW: I can not figure out, how I could check if tab or multitab has been occured if my callback has been invoked is this possible without breaking the encapsulation, while checking the mouse input?

My bad, i forgot i was using WasPressedThisFrame() on my input.
using triggered works!

using Input.actions["Fire"].triggered like the legacy input.getbutton works for me.

@LezTusi Thanks for the hint, but i’m not shure what you mean :wink:

Meanwhile I got the click handling working. I’ve extended my OnMove callback by using the CallbackContext parameter. Now I could check which Interaction has triggered the action and could it handle separately:

public void OnMove(InputAction.CallbackContext ctx){
        Debug.Log("OnMove callback invoked! ");

        if (ctx.interaction is TapInteraction) Debug.Log("Single tap trigger!");
        else if (ctx.interaction is MultiTapInteraction) Debug.Log("Multitap trigger!");
    }

Using this setup:

What I’ve figured out that the order of the interactions is strictly while those are executed from top down. If I use this set-up first the MultiMapInteraction is checked, if this interaction triggers the action, the other are not executed, if not, the next interaction (TapInteraction in my case) is executed and so on …

Not sure if this is an expected behaviour or a bug. I think it is a bug, I do not expect this behaviour and it is not documented. This also breaks the encapsulation, while I check the set up of a single action explicitly that was never in the mind of the inventor.

2 Likes

@Hellhound_01 i think id did not work in screenshot 1 because the tap interaction was on top of the multitap interaction. That way the successfull tap interaction “consumes” the input. If the multitap is on top like in the second screenshot it works because a failed multitap passes on the input to the tap interaction.

i need to have a tap interaction and a multi tap doing different things how do i achieve that

either its single tap and one function should be executed or its multi tap and another action should be triggered but right now both the actions are getting triggered

Is this still a bug? I’ve been having the same issues.

update

        public void DoubleClick(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Debug.Log("Action performed.");  
            }
        }

So using this code i got the correct behavior.

This somewhat works, but I am seeing that holding the button down also triggered the Tap action. I would expect it would not.

1 Like

when I press the button once, I get a double tap calling the function twice…
I cant really find a way to ask for a double tap using the new input system