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 42 43 44 45 46 47 48 49 50 51 52
| #include <windows.h>
#include "resource.h"
HHOOK hookClavier;
LRESULT CALLBACK fonctionIntercepteClavier (int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode >= 0)
{
if (wParam == 75) // 75 pour K
{
// action à effectuer
// return 1 si on veut empecher le traitement de K
}
}
return CallNextHookEx(hookClavier, nCode, wParam, lParam);
}
BOOL CALLBACK dialogProc(HWND handleDialog, UINT mssg, WPARAM wParam, LPARAM lParam)
{
switch(mssg)
{
case WM_INITDIALOG:
hookClavier = SetWindowsHookEx(WH_KEYBOARD, fonctionIntercepteClavier, NULL, GetCurrentThreadId());
if (!hookClavier)
MessageBox(0,"erreur de hook","",0x10);
return 1;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
MessageBox(0,"Boutton OK","",0x10);
return 1;
case IDCANCEL:
SendMessage(handleDialog,WM_QUIT,wParam,lParam);
return 1;
}
break;
case WM_CLOSE:
case WM_QUIT:
UnhookWindowsHookEx(hookClavier);
MessageBox(0,"Fin","",0x10);
PostQuitMessage(0);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
DialogBoxParam(hInstance, (LPCTSTR)IDD_DIALOG1, 0, dialogProc, 0);
return 1;
} |
Partager