Version: 2020.2

Event.KeyboardEvent

切换到手册
public static Event KeyboardEvent (string key);

描述

创建键盘事件。

当您需要检查某个键是否已被按下时,这很有用 - 可能具有修改键。键字符串的语法是键名称 (与 Input Manager 中的相同),可选择将任意数量的修改键作为前缀:\ & = Alternate,^ = Control,% = Command/Windows 键,# = Shift \ 示例:&f12 = Alternate + F12,"^[0]" = Control + keypad0。\

using UnityEngine;

public class Example : MonoBehaviour { // Detects if the shift key was pressed void OnGUI() { GUILayout.Label("Press Enter To Start Game");

if (Event.current.Equals(Event.KeyboardEvent("[enter]"))) { Application.LoadLevel(1); }

if (Event.current.Equals(Event.KeyboardEvent("return"))) { print("I said enter, not return - try the keypad"); } } }