Version: 2023.1
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.

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(); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961