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)
上一篇 2022年5月28日 下午11:36
下一篇 2022年5月28日 下午11:46


相关推荐

  • Java取余运算[通俗易懂]

    Java取余运算[通俗易懂]inta=6;~a=?Java中运算都是以补码进行计算的,6的原码为00000000000000000000000000000110,正数的补码=反码=原码所以补码也是00000000000000000000000000000110,然后进行取反操作变成了11111111111111111111111111111001,…

    2022年5月9日
    60
  • long型转String

    long型转Stringlonga1=12;Strings1=a1+””;//法1:直接加空串System.out.println(s1);longa2=34;Strings2=String.valueOf(a2);//法2:String.valueOf()System.out.pr…

    2022年5月15日
    40
  • 大数据要学哪些内容

    大数据要学哪些内容第一阶段:静态网页基础(HTML+CSS)1.难易程度:一颗星2.技术知识点+阶段项目任务+综合能力3.主要技术包括:html常用标签、CSS常见布局、样式、定位等、静态页面的设计制作方式等第二阶段:JavaSE+JavaWeb1.难易程度:两颗星2.技术知识点+阶段项目任务+综合能力3.主要技术包括:java基础语法、java面向对象(类、对象、封装、继承、多态、抽象…

    2022年4月26日
    70
  • 实操手册:移动云电脑怎么部署OpenClaw? 到底 可以接入OpenClaw的云产品有哪些?

    实操手册:移动云电脑怎么部署OpenClaw? 到底 可以接入OpenClaw的云产品有哪些?

    2026年3月13日
    2
  • redis如何设置密码及验证密码_redis如何设置密码及验证密码

    redis如何设置密码及验证密码_redis如何设置密码及验证密码在百度云安装redis服务之后,一直给我发送系统安全警告,推荐我redis设置访问密码,于是出于安全考虑我就设置一下redis的密码1.修改redis.conf配置文件:找到requirepass这一行,解注这一行代码,requirepass后面就是跟的自己的密码。2.关闭redis服务,发现报错:可以使用下面两个方法关闭服务:方式一:通过psaux|grepred…

    2025年9月15日
    7
  • 非常详细的rsyslogd配置文件解析

    非常详细的rsyslogd配置文件解析Rsyslog配置文件详解发表于2年前(2014-02-1017:25)  阅读(9805) | 评论(3) 10人收藏此文章, 我要收藏赞1rsyslog服务和logrotate服务======================================================================rsyslog是一个sysl

    2022年8月15日
    14

发表回复

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

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