Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Pen/Stylus input

Discussion in 'Input System' started by Progga2, Aug 6, 2020.

  1. Progga2

    Progga2

    Joined:
    Aug 6, 2020
    Posts:
    1
    Hello,
    I am trying to get pressure input from my Wacom tablet. According to the InputSystem documentation, it seems very easy and Wacom is even explicitely mentioned (https://docs.unity3d.com/Packages/com.unity.inputsystem@0.9/manual/Pen.html). However, I do not receive any values when trying to read anything from Pen.current (position, pressure etc). For instance, Pen.current.pressure.ReadValue() is always 0. The new input system is setup and otherwise works in my project (mouse, keyboard works and Pen is added as device).

    Interestingly, I literally found no example for pen/stylus input in Unity (or I used the wrong search terms) and very little on using pressure input in general. I have a running example in WPF, but that would be a lot of overhead to connect to Unity. Has anyone managed to get this to work directly in Unity using the new input system? Is there an initialization step that I am missing?

    Thanks,

    -Andreas
     
  2. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Bump, I'm having the same exact issue.
    Is there anything we're missing here?

    Thanks!
     
  3. claus_interactive

    claus_interactive

    Joined:
    Nov 22, 2018
    Posts:
    9
    Same here, happy about any input (pun intended). Is this a bug we should file? (no because it is a known issue, see below)
     
    Last edited: Mar 19, 2021
  4. claus_interactive

    claus_interactive

    Joined:
    Nov 22, 2018
    Posts:
    9
    Update:

    In the Input System docs, under "Known Limitations", it says:

    (Windows) Pen input will not work with Wacom devices if "Windows Ink" support is turned off.

    When I turn Windows Ink on in the Wacom Tablet Settings, and then restart all Unity Instances, I get pen pressure readings. But there is a reason all of us have "Windows Ink" off - it just ... doesn't work very well.

    Big Bummer: When I turn Windows Ink on, I cannot press anything inside Unity's own UI using the Wacom pen (like the "Play" button or anything in the inspector.. Does anyone have a solution for this?
     
    Last edited: Mar 19, 2021
  5. claus_interactive

    claus_interactive

    Joined:
    Nov 22, 2018
    Posts:
    9
    Here's a little snippet with some info for testing:
    Unity version used: 2020.2.1f1, Input System Package 1.0.2

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class InputTest : MonoBehaviour {
    5.    
    6.     // look in the inspector to see the values update
    7.     public float pointerPressure = 0;
    8.     public bool pointerPressed;
    9.  
    10.     public float penPressure = 0;
    11.  
    12.     public bool penTipPressed;
    13.     public bool penIsHovering;
    14.  
    15.     public Vector2 mousePos;
    16.  
    17.     void Update() {
    18.         // "Pen", "Pointer" and "Mouse" must be added to "Supported Devices" in "Project Settings"->"Input System Package"
    19.         // for being available for use
    20.         Pointer pointer = Pointer.current;
    21.         Pen pen = Pen.current;
    22.         Mouse mouse = Mouse.current;
    23.  
    24.         // only returns a value >0 until pointer is moved after pressing
    25.         pointerPressure = pointer.pressure.ReadValue();
    26.      
    27.         // works
    28.         pointerPressed = pointer.press.isPressed;
    29.  
    30.         // works, iff:
    31.         // - Windows Ink is on in Wacom Tablet Properties
    32.         //   note: all Unity instances must be restarted after toggling this setting
    33.         penPressure = pen.pressure.ReadValue();
    34.         penTipPressed = pen.tip.isPressed;
    35.         penIsHovering = pen.inRange.isPressed;
    36.      
    37.         // works (if Mouse is added to Suported Devices)
    38.         if (mouse != null) {
    39.             mousePos = mouse.position.ReadValue();
    40.          
    41.         }
    42.     }
    43. }
    44.  
     
    Last edited: Mar 19, 2021
  6. jesperhylbaek

    jesperhylbaek

    Joined:
    Dec 6, 2017
    Posts:
    1
    Any news on this?
    I too can not get my wacom pen to work probably.
    Either i can not right click, that is fixed by turning windows ink on in Wacom settings, but then I can not select anything left clicking in Unity.
    My wacom pen is useless, and I really, really want to it to work :(
     
  7. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Also experiencing the same issues with wacom tablet

    -windows ink on: able to read pen input in-game, but cannot click Unity UI
    -windows ink off: able to click Unity UI, but cannot use in-game

    Unity should definitely find a mode that works for both
     
  8. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    158
    The same here. I was thinking about simulating mouse events as a workaround. Thus I can still use pen features like pressure with Windows Ink enabled. Just put it in Update method.
    upload_2021-11-15_22-25-46.png
     
  9. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    158
    I can also confirm that this issue happens with Dell Active Pen in Windows 10 that works via MPP (Microsoft Pen Protocol). Here is what happened when the pen touches the screen. We have inRange, pressure and coordinates, but not a PRESS FACT. Windows Ink is enabled in this case. Disabling Windows Ink or turning ON Mouse Mode makes it working as a mouse, but we can no longer get pressure and other pen-specific values.

     
  10. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    158
  11. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    134
    In the latest alpha 2022.1.0a15.2209 my pen now works in the editor, but now at runtime it's constantly sending me PointerUpEvents for the pen, then sending mouse events instead of pen events for a few frames (using the pen's position but with 0 pressure), and then switching back to the pen.
     
    Lars-Steenhoff likes this.
  12. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    158
    Please create a bug, they may not read this forum.
     
  13. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,190
  14. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,190
  15. BorisNG

    BorisNG

    Joined:
    Feb 9, 2021
    Posts:
    4
    Amazing! thanks a lot, i have a HUION tablet and the same problem. your code helped me fix some of it, thanks again!
     
  16. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,190
  17. KevinWelton

    KevinWelton

    Unity Technologies

    Joined:
    Jul 26, 2018
    Posts:
    214
    Pressure should work in 2022.1+.

    Keep in mind that we currently only support reading pen-specific metrics with Windows Ink. We don't support wintab as retrofitting it would have been incredibly costly resource-wise.
     
    Lars-Steenhoff likes this.
  18. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,190
    Yes its working! Could you please add an example in the docs ?
    so people who want to integrate it can do so easily
    Thanks!
     
  19. KevinWelton

    KevinWelton

    Unity Technologies

    Joined:
    Jul 26, 2018
    Posts:
    214
    BTW, there are a lot of pen improvements in 2022. This includes some support for pen input in the editor as well.

    Many of the features are new to 2022, however, and won't be backported.
     
    Lars-Steenhoff likes this.
  20. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,190

    Yes the editor has support now, will the terrain painting and polybtush also get official pressure support?

    I have this running with YAPP and like to see more unity tools support it
     
    KevinWelton likes this.
  21. KevinWelton

    KevinWelton

    Unity Technologies

    Joined:
    Jul 26, 2018
    Posts:
    214
    Awesome video. I'm sending this to the devs who implemented the feature so they can see it in action.

    My suggestion if you would like built in pen support for the tools you mention is to head over to the world building forum. Relevant feature developers can better prioritize their feature work when they have data directly from users.
     
unityunity