Version: Unity 6 Preview (6000.0)
LanguageEnglish
  • C#

Input.GetPenEvent

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static PenData GetPenEvent(int index);

Returns

PenData Pen event details in the struct.

Description

Returns the PenData for the pen event at the given index in the pen event queue.

Note: This API is part of the legacy Input class, and not recommended for new projects. The documentation is provided here to support legacy projects that use the old Input Manager and Input class. For new projects you should use the newer and Input System Package. (read more).

On Windows, the pen event queue holds, in chronological order, any missed pen events as provided by GetPointerPenInfoHistory. The queue is cleared at the end of each frame. On all other platforms the queue will always be empty.

using UnityEditor;
using UnityEngine;

public class Example : EditorWindow { [MenuItem("Window/Pen Window")] public static void ShowWindow() { EditorWindow win = EditorWindow.GetWindow(typeof(Example)); win.titleContent = new GUIContent("Pen Window"); win.wantsMouseMove = true; }

void OnGUI() { var e = Event.current; if ((e.type == EventType.MouseDown || e.type == EventType.MouseDrag || e.type == EventType.MouseDown || e.type == EventType.MouseUp || e.type == EventType.MouseMove) && (e.pointerType == PointerType.Pen)) { int count = Input.penEventCount; for (int i = 0; i < count; i++) { // Log data from queued pen events PenData p = Input.GetPenEvent(i); Debug.Log($"Pen position {p.position}, pen pressure {p.pressure}, pen twist {p.twist}, pen tilt {p.tilt}, pen status - barrel {(p.penStatus & PenStatus.Barrel) != 0}"); } Input.ResetPenEvents(); } } }