docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Pen

    Represents a pen/stylus input device.

    Inheritance
    object
    InputControl
    InputDevice
    Pointer
    Pen
    Implements
    IInputStateCallbackReceiver
    Inherited Members
    Pointer.position
    Pointer.delta
    Pointer.radius
    Pointer.pressure
    Pointer.press
    Pointer.displayIndex
    Pointer.OnNextUpdate()
    Pointer.OnStateEvent(InputEventPtr)
    InputDevice.InvalidDeviceId
    InputDevice.description
    InputDevice.enabled
    InputDevice.canRunInBackground
    InputDevice.added
    InputDevice.remote
    InputDevice.native
    InputDevice.updateBeforeRender
    InputDevice.deviceId
    InputDevice.lastUpdateTime
    InputDevice.wasUpdatedThisFrame
    InputDevice.allControls
    InputDevice.valueType
    InputDevice.valueSizeInBytes
    InputDevice.ReadValueFromBufferAsObject(void*, int)
    InputDevice.ReadValueFromStateAsObject(void*)
    InputDevice.ReadValueFromStateIntoBuffer(void*, void*, int)
    InputDevice.CompareValue(void*, void*)
    InputDevice.OnAdded()
    InputDevice.OnConfigurationChanged()
    InputDevice.ExecuteCommand<TCommand>(ref TCommand)
    InputDevice.ExecuteCommand(InputDeviceCommand*)
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.this[string]
    InputControl.magnitude
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(void*)
    InputControl.WriteValueFromBufferIntoState(void*, int, void*)
    InputControl.WriteValueFromObjectIntoState(object, void*)
    InputControl.TryGetChildControl(string)
    InputControl.TryGetChildControl<TControl>(string)
    InputControl.GetChildControl(string)
    InputControl.GetChildControl<TControl>(string)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    InputControl.optimizedControlDataType
    InputControl.CalculateOptimizedControlDataType()
    InputControl.ApplyParameterChanges()
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.dll
    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

    this[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
    Exceptions
    Type Condition
    ArgumentException

    button is not a valid pen button.

    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
    Eraser

    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
    BarrelFirst

    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
    BarrelFourth

    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
    InRange

    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
    BarrelSecond

    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
    BarrelThird

    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
    Tip

    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
    Pointer.FinishSetup()
    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");
             }
         }</code></pre></example>
    

    MakeCurrent()

    Make this the last used pen, i.e. current.

    Declaration
    public override void MakeCurrent()
    Overrides
    Pointer.MakeCurrent()
    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()
    Overrides
    Pointer.OnRemoved()

    Implements

    IInputStateCallbackReceiver

    Extension Methods

    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, void*, void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*, void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, void*)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, bool>)
    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInState(InputControl, void*)
    InputControlExtensions.IsActuated(InputControl, float)
    InputControlExtensions.IsPressed(InputControl, float)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, void*, int)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, object)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState(InputControl, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, void*)
    InputControlExtensions.CopyState(InputDevice, void*, int)
    InputControlExtensions.CopyState<TState>(InputDevice, out TState)
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)