Class Pen
Represents a pen/stylus input device.
Inherited Members
Namespace: UnityEngine.InputSystem
Syntax
public class Pen : Pointer, IInputStateCallbackReceiver
Remarks
Unlike mice but like touch, pens are absolute pointing devices moving across a fixed surface area.
The tip acts as a button that is considered pressed as long as the pen is in contact with the tablet surface.
Properties
current
The pen that was active or connected last or null
if there is no pen.
Declaration
public static Pen current { get; }
Property Value
Type | Description |
---|---|
Pen |
eraser
The eraser button of the pen, i.e. the button on the end opposite to the tip.
Declaration
public ButtonControl eraser { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the eraser button. |
Remarks
If the pen does not have an eraser button, this control will still be present but will not trigger.
See Also
firstBarrelButton
The button on the side of the pen barrel and located closer to the tip of the pen.
Declaration
public ButtonControl firstBarrelButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the first side button. |
Remarks
If the pen does not have barrel buttons, this control will still be present but will not trigger.
See Also
fourthBarrelButton
Fourth button the side of the pen barrel.
Declaration
public ButtonControl fourthBarrelButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the fourth side button. |
Remarks
If the pen does not have a fourth barrel buttons, this control will still be present but will not trigger.
See Also
inRange
Button control that indicates whether the pen is in range of the tablet surface or not.
Declaration
public ButtonControl inRange { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl |
Remarks
This is a synthetic control (synthetic).
If range detection is not supported by the pen, this button will always be "pressed".
See Also
Item[PenButton]
Return the given pen button.
Declaration
public ButtonControl this[PenButton button] { get; }
Parameters
Type | Name | Description |
---|---|---|
PenButton | button | Pen button to return. |
Property Value
Type | Description |
---|---|
ButtonControl |
secondBarrelButton
The button on the side of the pen barrel and located closer to the eraser end of the pen.
Declaration
public ButtonControl secondBarrelButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the second side button. |
Remarks
If the pen does not have barrel buttons, this control will still be present but will not trigger.
See Also
thirdBarrelButton
Third button the side of the pen barrel.
Declaration
public ButtonControl thirdBarrelButton { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the third side button. |
Remarks
If the pen does not have a third barrel buttons, this control will still be present but will not trigger.
See Also
tilt
Orientation of the pen relative to the tablet surface, i.e. the amount by which it is leaning over along the X and Y axis.
Declaration
public Vector2Control tilt { get; protected set; }
Property Value
Type | Description |
---|---|
Vector2Control | Control presenting the amount the pen is leaning over. |
Remarks
X axis goes from [-1..1] left to right with -1 and 1 meaning the pen is flush with the tablet surface. Y axis goes from [-1..1] bottom to top.
tip
The tip button of the pen.
Declaration
public ButtonControl tip { get; protected set; }
Property Value
Type | Description |
---|---|
ButtonControl | Control representing the tip button. |
See Also
twist
Rotation of the pointer around its own axis. 0 means the pointer is facing away from the user (12 'o clock position) and ~1 means the pointer has been rotated clockwise almost one full rotation.
Declaration
public AxisControl twist { get; protected set; }
Property Value
Type | Description |
---|---|
AxisControl | Control representing the twist of the pen around itself. |
Remarks
Twist is generally only supported by pens and even among pens, twist support is rare. An example product that supports twist is the Wacom Art Pen.
The axis of rotation is the vector facing away from the pointer surface when the pointer is facing straight up (i.e. the surface normal of the pointer surface). When the pointer is tilted, the rotation axis is tilted along with it.
Methods
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}
MakeCurrent()
Make this the last used pen, i.e. current.
Declaration
public override void MakeCurrent()
Overrides
Remarks
This is called automatically by the system when a pen is added or receives input.
OnRemoved()
Called when the pen is removed from the system.
Declaration
protected override void OnRemoved()