zoukankan      html  css  js  c++  java
  • Unity 实现模拟按键

    一直在想,使用模拟按键,也可以实现一些AI操作,具体还没做过,这里使用user32.dll在unity里写的一个简单demo

    using UnityEngine;
    using System.Collections;
    using System.Runtime.InteropServices;
    
    public class GetKeyCodeKey : MonoBehaviour {
    
        [DllImport("user32.dll", EntryPoint = "keybd_event")]
        public static extern void keybd_event(
    
                byte bVk,    //虚拟键值 对应按键的ascll码十进制值
    
                byte bScan,// 0
    
                int dwFlags,  //0 为按下,1按住,2为释放
    
                int dwExtraInfo  // 0
    
            );         
    
    
    	// Use this for initialization
    	void Start () {
            	keybd_event(65, 0, 0, 0);
            	keybd_event(65, 0, 1, 0);
            	keybd_event(65, 0, 2, 0);
    	}
    	
    	// Update is called once per frame
    	void Update () {
            	if (Input.GetKeyDown(KeyCode.A))
            	{
                		Debug.Log("按下了A键");
            	}
            	if (Input.GetKey(KeyCode.A))
            	{
                		Debug.Log("按住了A键");
            	}
    
    		if (Input.GetKey(KeyCode.A))        
    		{            
    			Debug.Log("按住了A键");        
    		}	
         	}
    }
    
    



     

  • 相关阅读:
    springboot运行在eclipse报异常的问题
    Python random模块
    MySQL大小写敏感
    正则表达式详解
    Linux grep命令详解
    Linux printf命令详解
    Linux awk命令详解
    MySQL表介绍
    Linux sed命令详解
    Linux grep命令详解
  • 原文地址:https://www.cnblogs.com/liang123/p/6325916.html
Copyright © 2011-2022 走看看