Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help needed with WSANative plugin to listen Surface Pen events

Discussion in 'Windows' started by JariHuomo, Feb 23, 2021.

  1. JariHuomo

    JariHuomo

    Joined:
    Feb 8, 2013
    Posts:
    48
    Hi guys,

    Using WSANative plugin to check if a Surface user is using Surface Pen eraser on my coloring application.
    https://github.com/ClaytonIndustries/WSANative/wiki/Input

    Is this possible to get working with il2cpp?
    Or any other way to check if Pen is used?

    From MainPage.xaml.cs
    private void ConfigureInput()
    {

    Window.Current.CoreWindow.PointerPressed += (s, e) =>
    {
    if (WSANativeInput.PointerPressed != null)
    {
    PointerPointProperties pointerProperties = e.CurrentPoint.Properties;
    try
    {
    WSANativeInput.PointerPressed(new WSAPointerProperties()
    {
    InputType = e.CurrentPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Touch ? WSAInputType.Touch :
    e.CurrentPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Pen ? WSAInputType.Pen : WSAInputType.Mouse,
    IsLeftButtonPressed = pointerProperties.IsLeftButtonPressed,
    IsRightButtonPressed = pointerProperties.IsRightButtonPressed,
    IsEraser = pointerProperties.IsEraser,
    IsInverted = pointerProperties.IsInverted
    });
    }
    catch
    {

    }

    }
    };

    }
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    You can just use that code from your Unity C# script in some Awake() method. You'll need to wrap it in #if ENABLE_WINMD_SUPPORT/#endif define. You will also need to make sure that it's called from the right thread by using UnityEngine.WSA.Application.InvokeOnUIThread.

    Lastly, you may want to use CoreWindow.GetForCurrentThread() instead of Window.Current - the latter only works if you use XAML build type, while the former works on D3D/ExecutableOnly app types too.
     
  3. JariHuomo

    JariHuomo

    Joined:
    Feb 8, 2013
    Posts:
    48
    Thank you very much!