Detect touch up/release when using Touchscreen

All of these return true when I release my finger. How can I detect when a touch is released?

InputSystem.onEvent += ( eventPtr, device ) =>
{
    if( !eventPtr.IsA<StateEvent>() && !eventPtr.IsA<DeltaStateEvent>() )
        return;

    var touchscreen = device as Touchscreen;
    if( touchscreen == null )
        return;

    Debug.Log( "IsPressed:" + touchscreen.primaryTouch.IsPressed() );
    Debug.Log( "press:" + touchscreen.primaryTouch.press.ReadValue() );
    Debug.Log( "isInProgress:" + touchscreen.primaryTouch.isInProgress );
    Debug.Log( "IsActuated:" + touchscreen.primaryTouch.IsActuated() );
};

I am using Input System Version 1.1.0-preview.3 and Unity 2019.4.16.f1.

I have been looking into InputSystem and was thinking how to get it to send a Unity event on the release of a mouse button. Adding an interaction allowed me to do that. I added it to a Click binding, so I have separate methods for mouse down (in the Fire binding) and mouse up (in the Click binding).

Here’s the code I’m testing with:

using UnityEngine.InputSystem;
using UnityEngine;

public class MouseReader : MonoBehaviour
{
    Mouse mouse;

    void Start()
    {
        mouse = Mouse.current;
        Debug.Log(mouse);
    }

    public void OnFire()
    {
        Debug.LogFormat("OnFire: {0}", mouse.clickCount.ReadValue());
    }

    public void OnClick()
    {
        Debug.LogFormat("OnClick: {0}", mouse.clickCount.ReadValue());
    }
}

Maybe something like that will work for you.

1 Like