#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;
HHOOK g_hKeyboard;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
PMSLLHOOKSTRUCT pmll = (PMSLLHOOKSTRUCT) lParam;
printf("msg: %lu, x:%ld, y:%ld\n", wParam, pmll->pt.x, pmll->pt.y);
}
return CallNextHookEx(g_hKeyboard, nCode, wParam, lParam);
}
int main(void)
{
MSG msg;
g_hKeyboard = SetWindowsHookEx( WH_KEYBOARD_LL, KeyboardProc, GetModuleHandle(NULL), 0 );
if (!g_hKeyboard) printf("Hook error: %d\n", GetLastError());
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(g_hKeyboard);
return (int) msg.wParam;
}
附件:msdn 上对于这些数值的定义
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
);
wParam
[in] Specifies the virtual-key code of the key that generated the keystroke message.
lParam
[in] Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. This parameter can be one or more of the following values
欢迎光临 Code Lyoko CN - 中国虚幻勇士(至Net奇兵)交流论坛 (http://bbs.lyokocn.com/) | Powered by Discuz! 7.2 |