在之前开发一些硬件设备的时候,会有一些设备的物理按键不知道键值是什么,然后写了一个简单的测试方法。代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
/// <summary>
/// 得到输入
/// </summary>
public class GetKeyValue : MonoBehaviour
{
private void Update ()
{
if (Input.anyKeyDown)
{
foreach (KeyCode keycode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyDown(keycode))
{
Debug.Log("Current Key is : " + keycode.ToString());
}
}
}
}
}