VB2010VBNET源码 HOOK 键盘钩子

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

'***************************'模块代码Module1'***************************OptionExplicitPrivateDeclareFunctionCallNextHookExLibuser32_(ByValhHookAsLong,_ByValnCodeAsLong,_ByValwParamAsLong,_lParamAsAny)AsLongPrivateDeclareFunctionSetWindowsHookExLibuser32_AliasSetWindowsHookExA_(ByValidHookAsLong,_ByVallpfnAsLong,_ByValhmodAsLong,_ByValdwThreadIdAsLong)AsLongPrivateDeclareFunctionUnhookWindowsHookExLibuser32_(ByValhHookAsLong)AsLongPrivateDeclareSubCopyMemoryLibkernel32_AliasRtlMoveMemory_(DestinationAsAny,_SourceAsAny,_ByValLengthAsLong)PrivateTypePKBDLLHOOKSTRUCTvkCodeAsLongscanCodeAsLongflagsAsLongtimeAsLongdwExtraInfoAsLongEndTypePrivateConstWM_KEYDOWN=&H100PrivateConstWM_SYSKEYDOWN=&H104PrivateConstWM_KEYUP=&H101PrivateConstWM_SYSKEYUP=&H105PrivateConstVK_LWIN=&H5BPrivateConstVK_RWIN=&H5CPrivateConstHC_ACTION=0PrivateConstWH_KEYBOARD_LL=13PrivateConstVK_CONTROL=&H11PrivateConstVK_ESCAPE=&H1BPrivateConstVK_MENU=&H12PrivateConstVK_TAB=&H9PrivateConstVK_Delete=&H2EPrivatelngHookAsLong'使用底层KeyboardHook拦截按键消息PublicFunctionLowLevelKeyboardProc(ByValnCodeAsLong,_ByValwParamAsLong,_ByVallParamAsLong)AsLongDimblnHookAsBooleanDimpAsPKBDLLHOOKSTRUCTIfnCode=HC_ACTIONThenSelectCasewParamCaseWM_KEYDOWN,WM_SYSKEYDOWN,WM_KEYUP,WM_SYSKEYUPCallCopyMemory(p,ByVallParam,Len(p))Ifp.vkCode=VK_LWINOrp.vkCode=VK_RWINThenblnHook=True'按下了左/右Win键Ifp.vkCode=VK_CONTROLOrp.vkCode=VK_ESCAPEThenblnHook=True'按下了Ctrl+Esc键Ifp.vkCode=VK_MENUOrp.vkCode=VK_TABThenblnHook=True'按下了Alt+Tab键CaseElse'donothingEndSelectEndIfIfblnHookThenLowLevelKeyboardProc=1ElseCallCallNextHookEx(WH_KEYBOARD_LL,nCode,wParam,lParam)EndIfEndFunctionPublicSubHooK()lngHook=SetWindowsHookEx(WH_KEYBOARD_LL,_AddressOfLowLevelKeyboardProc,_App.hInstance,_0)EndSubPublicSubUnHooK()CallUnhookWindowsHookEx(lngHook)EndSub'***************************'窗体代码Form1'***************************PrivateSubForm_Load()CallHooK'屏蔽Win键EndSubPrivateSubForm_Unload(CancelAsInteger)CallUnHooK'取消屏蔽Win键EndSub这只是简单的屏蔽了几个键,当然如果要屏蔽更多的键,只要在模块的LowLevelKeyboardProc函数中设置你想要拦截键盘键值过滤掉就可以了。

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功