Our game works great with touch or mouse, but the Surface pen doesn't seem to register as a pointing device at all. How can we support the pen in Unity in a native build?

This question on the Unity Answers site suggests we could build it as a UWP app, but that means restricting ourselves to a very limited subset of the .NET framework (specifically, we lose a lot of the Serialization libraries).

  • \$\begingroup\$ Can you just treat it as touch input? \$\endgroup\$
    – Evorlor
    Commented May 22, 2017 at 12:56
  • \$\begingroup\$ @Everlor, it doesn't register to Unity as touch input. If you know how to make it do so, that would be awesome. \$\endgroup\$ Commented May 22, 2017 at 20:03
  • \$\begingroup\$ @ArcaneEngineer I'm not sure; at the moment (1) is looking very tricky and I'm not sure how to do (2) at all. Supporting one of an OS's built-in input systems doesn't seem like it should be particularly difficult, but I'm unable to find resources on it at all. \$\endgroup\$ Commented May 25, 2017 at 18:18
  • 2
    \$\begingroup\$ I've found no answers elsewhere, like you. For (2), you'd need a DLL called by your Unity app, or a Windows service (or Win application if a service won't do the job) running alongside your app. You'd need to grab the inputs in that service/app, from the appropriate Microsoft API (Pen, I think), and route that data to your Unity application via IPC. DLL hooking into Unity direct looks easier. But could it get access to the API in question? - I'm not sure. \$\endgroup\$
    – Engineer
    Commented May 30, 2017 at 10:08
  • 1

1 Answer 1


On my SP3 the pen works with https://docs.unity3d.com/ScriptReference/Input-mousePosition.html and returns a Vector3 with x, y and 0z co-ordinates. I'm using Unity 5.6 on Linux but if the pen doesn't show up as touch input in Windows I would assume it has the same behavior.

  • \$\begingroup\$ Awesome! Pen position does indeed get reported, but I didn't realize it because pen taps don't register as mouse clicks. Do you have any insight as to how to recognize pen taps as mouse clicks (or any sort of input)? \$\endgroup\$ Commented Jun 3, 2017 at 19:54
  • 1
    \$\begingroup\$ You could maybe do something hacky with detecting when the pen stops moving but I haven't found anything in the Unity input api that properly detects the taps. I think you would have to use one of @Arcane Engineer's suggestions and use something external that passes the data into your game. \$\endgroup\$ Commented Jun 4, 2017 at 0:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .