using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class KeybdEvent : MonoBehaviour {
[DllImport("user32.dll", EntryPoint = "keybd_event")]
public static extern void Keybd_event(
byte bvk,//虚拟键值 ESC键对应的是27
byte bScan,//0
int dwFlags,//0为按下,1按住,2释放
int dwExtraInfo//0
);
void Start()
{
Keybd_event(27,0,0,0);
Keybd_event(27, 0, 1, 0);
Keybd_event(27, 0, 2, 0);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
print("按下了ESC键");
}
if (Input.GetKey(KeyCode.Escape))
{
print("按住了ESC键");
}
if(Input.GetKeyUp(KeyCode.Escape))
{
print("松开了ESC键");
}
}
}
按下一定要记得释放,否则你会体会到键盘失灵的感觉。。。