Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 在GUI.text区域中查找Unity3D中按下的组合键_User Interface_Unity3d - Fatal编程技术网

User interface 在GUI.text区域中查找Unity3D中按下的组合键

User interface 在GUI.text区域中查找Unity3D中按下的组合键,user-interface,unity3d,User Interface,Unity3d,如何跟踪用户在GUI.TextArea中按下了Crtl+Enter?我找到了一种方法,通过使用Event.current,知道按下了一个键,但这显然不适用于组合键。选项1 使用事件: if (Event.current.control && Event.current.keyCode == KeyCode.Return) Debug.Log("Ctrl+Enter is pressed!"); 此条件检查是否现在按Ctrl+Enter组合键(即在当前

如何跟踪用户在
GUI.TextArea
中按下了
Crtl
+
Enter
?我找到了一种方法,通过使用
Event.current
,知道按下了一个键,但这显然不适用于组合键。

选项1 使用事件:

if (Event.current.control && Event.current.keyCode == KeyCode.Return)
    Debug.Log("Ctrl+Enter is pressed!");
此条件检查是否现在按Ctrl+Enter组合键(即在当前帧上)。 当按下Ctrl+Enter(即连续)时,此检查将在每一帧上返回true

选择2 使用:

此条件仅在实际按键发生的帧上满足(即每次输入按键一次)

牢记 请记住,
OnGUI
可以(在键盘输入的情况下)一帧调用多次。选中
Event.current.type
以获取调用OnGUI的原因

    bool controlIsPressed = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
    if (Input.GetKeyDown(KeyCode.Return) && controlIsPressed)
        Debug.Log("Ctrl+Enter was pressed");