1个回答
2013-10-13
展开全部
// S:~ 这是我以前写过的一个键盘钩子,供lz参考
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
HHOOK hHook;
LRESULT CALLBACK LLKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT pkl = (PKBDLLHOOKSTRUCT)lParam;
TCHAR buffer[123];
if(nCode >= HC_ACTION
&& !(pkl->flags & 0x80)) {
sprintf(buffer, "你按下了%c键哦", pkl->vkCode);
MessageBox(NULL, buffer, TEXT("钩子"), MB_OK);
return TRUE;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int main()
{
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LLKeyBoardProc, GetModuleHandle(NULL), 0);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
DispatchMessage(&msg);
UnhookWindowsHookEx(hHook);
}
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
HHOOK hHook;
LRESULT CALLBACK LLKeyBoardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT pkl = (PKBDLLHOOKSTRUCT)lParam;
TCHAR buffer[123];
if(nCode >= HC_ACTION
&& !(pkl->flags & 0x80)) {
sprintf(buffer, "你按下了%c键哦", pkl->vkCode);
MessageBox(NULL, buffer, TEXT("钩子"), MB_OK);
return TRUE;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int main()
{
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LLKeyBoardProc, GetModuleHandle(NULL), 0);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
DispatchMessage(&msg);
UnhookWindowsHookEx(hHook);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询