Hvis jeg husker ret skulle programmet fange muse-events og ikke keyboard events?
I så fald skal det være WH_MOUSE_LL i kaldet til SetWindowsHookEx og ikke WH_KEYBOARD_LL.
Jeg lavede en lidt udvidet version der udskriver typen på eventen:
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
HHOOK MouseHook;
LRESULT LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HC_ACTION)
{
MSLLHOOKSTRUCT *HookStruct = (MSLLHOOKSTRUCT *)lParam;
std::ofstream File("C:/koord.txt", std::ios::app);
switch(wParam)
{
case WM_LBUTTONDOWN:
File << "LBUTTONDOWN: ";
break;
case WM_LBUTTONUP:
File << "LBUTTONUP: ";
break;
case WM_MOUSEMOVE:
File << "MOUSEMOVE: ";
break;
case WM_MOUSEWHEEL:
File << "MOUSEWHEEL: ";
break;
case WM_RBUTTONDOWN:
File << "RBUTTONDOWN: ";
break;
case WM_RBUTTONUP:
File << "RBUTTONUP: ";
break;
default:
File << "Unknown: ";
break;
}
File << HookStruct->pt.x << ", " << HookStruct->pt.y << std::endl;
}
return CallNextHookEx(MouseHook, nCode, wParam, lParam);
}
void InstallHook(void)
{
if(MouseHook)
return;
MouseHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC )LowLevelMouseProc, GetModuleHandle(0), 0);
if(!MouseHook)
{
MessageBox(0, "Failed to install Hook", "PageDown Remover", MB_OK);
}
}
void UnInstallHook(void)
{
if(MouseHook)
UnhookWindowsHookEx(MouseHook);
MouseHook = 0;
}
int main()
{
remove("C:/koord.txt");
InstallHook();
MessageBox(0, "Hit Ok to close", "PageDown Remover", MB_OK);
UnInstallHook();
return EXIT_SUCCESS;
}