1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
//make sure system is windows.
#include <windows.h>
LRESULT CALLBACK newKeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//these values came from
//a different hook which saved values
//of WM_ down & up to a file.
KBDLLHOOKSTRUCT kbd;
ZeroMemory(&kbd,sizeof(KBDLLHOOKSTRUCT));
kbd.dwExtraInfo = 0;
kbd.flags = 0;
kbd.scanCode = 30;
kbd.time = GetMessageTime();
kbd.vkCode = 65;
// Below is my futile attempt to have the normal hook
//process my fake message.
CallNextHookEx(NULL,0, WM_KEYDOWN, reinterpret_cast<LPARAM>(&kbd));
kbd.flags = 128;
kbd.time = GetMessageTime();
CallNextHookEx(NULL,0, WM_KEYUP, reinterpret_cast<LPARAM>(&kbd));
return CallNextHookEx(NULL,nCode,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HHOOK keyboardHook =
SetWindowsHookEx(WH_KEYBOARD_LL,
newKeyboardHookProc,
hInstance,
NULL);
MessageBox(NULL, L"Press OK to close.", L"", MB_OK);
UnhookWindowsHookEx(keyboardHook);
return 0;
}
|