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); 

}

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

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