Unity键盘钩子[通俗易懂]

Unity键盘钩子[通俗易懂]http://blog.csdn.net/qq452626100/article/details/52398830privatestaticintKeyboardHookProc(intnCode,Int32wParam,IntPtrlParam){ if(nCode==HC_ACTION ) { varkc=(KeyCode)(wParam+97-65)

大家好,又见面了,我是你们的朋友全栈君。

http://blog.csdn.net/qq452626100/article/details/52398830

private static int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
	if (nCode == HC_ACTION	)
	{
		var kc = (KeyCode)(wParam+97-65);

		// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644984(v=vs.85).aspx
		int int32Param = lParam.ToInt32();
		var repeat_count	= (ushort) (int32Param&		0xFFFF); //0 - 15	The repeat count.The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
		var scan_code		= (ushort)((int32Param&	  0xFF0000)>>16); //16 - 23The scan code.The value depends on the OEM.
		var extended_key	= 0!=  ((int32Param&  0x1000000)>>24); //24 Indicates whether the key is an extended key, such as a function key or a key on the numeric keypad.The value is 1 if the key is an extended key; otherwise, it is 0.
		var reserved		= (ushort)((int32Param&	0x1E000000)>>25); //25 - 28Reserved.
		var context_code	= 0!=  ((int32Param&	0x20000000)>>29); //29The context code.The value is 1 if the ALT key is down; otherwise, it is 0.
		var previous_key_state=0!= ((int32Param&	0x40000000)>>30); //30The previous key state.The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
		var transition_state= 0!=  ((int32Param&	0x80000000)>>31);//31	The transition state. The value is 0 if the key is being pressed and 1 if it is being released.

		if( !previous_key_state && !transition_state)//有键按下
		{
			Debug.Log ("钩子键盘按下:"+kc);
		}
		else if( previous_key_state && transition_state)
		{
			Debug.Log ("钩子键盘抬起:"+kc);
		}
		return 1;
	}

	return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); 

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/139934.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • docker pull image 打tag

    docker pull image 打tag

    2021年5月14日
    140
  • wd移动硬盘测试软件,西数硬盘修复工具(WD HDD Repair Tools)「建议收藏」

    WDHDDRepairTools是西部数据(WD)官方发布的一款西数硬盘检测修复工具,它可显示寄存器状态,支持WD-L/WD-ROYL板,能进行硬盘软复位,可识别硬盘,查看或清除SMART,起转电机及直接复位,加载瞬时及永久覆盖,操作磁道、FLASH及模块。改变内存中的磁头位置,编辑列表,设置最高容量及目标容量。格式化硬盘/保留区,校验伺服系统及磁头。清除异常中断代码及软件错误数。重新构…

    2022年4月16日
    896
  • 下载Android SDK tools完成Android SDK 安装、配置环境变量

    下载Android SDK tools完成Android SDK 安装、配置环境变量大家都知道安卓是基于java开发的,安卓因为其开放包容的特性被广大的程序员所青睐。早期,开发Android用到IDE是开源的eclipse,同时Android为eclipse提供了开发用的插件,这促使了安卓的发展。随着Android的过于开放,导致Android吃硬件性能越来越厉害。现在,为了解决性能上面的缺陷,Google慢慢的开始收紧了对Android的控制。于是Google研发了自家的AndroidStudio。随着时间的发展,AndroidStudio越来越成熟。

    2022年7月21日
    19
  • net use * /del_想打开文件但显示遇到问题需要关闭

    net use * /del_想打开文件但显示遇到问题需要关闭近日公司电脑大面积瘫痪,杀毒软件不停弹出提示有病毒被查杀,并且经常弹出提示:GenericHostProcessforWin32Services遇到问题需要关闭,server和workstation服务自动停止,客户端连不上域。一下被搞的手忙脚乱,几经周折才查出原因,打了补丁后问题解决。表现  在开机后可能会出现多次“GenericHostProcessforW

    2022年10月12日
    1
  • java中import作用详解

    java中import作用详解java中import详解import与package机制相关,这里先从package入手,再讲述import以及staticimport的作用。

    2022年6月7日
    26
  • Linux中公钥和私钥原理

    Linux中公钥和私钥原理原文 公钥和私钥原理一直以来对公钥和私钥都理解得不是很透彻 感觉到模棱两可 心里直打鼓呢 公钥怎么会事 私钥怎么会事 工作原理是怎么的 今天在网上找了半天 通过查看大家对这个密钥对的理解 总算弄清楚了 咱就把我的心得写出来给大家对密钥对有疑问的同志们看看 nbsp nbsp nbsp nbsp nbsp nbsp 公钥和私钥就是俗称的不对称加密方式 是从以前的对称加密 使用用户名与密码 方式的提高 我用电子邮件的方式说明一下原理 nbsp nbsp nbsp

    2025年8月18日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号