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
| void hookClavier() {
HWND hWindow;
DWORD threadID;
HHOOK clavier;
hWindow=GetForegroundWindow(); // On recupere le handle de la fenetre au premier plan
printf("le handle de la fenetre au premier plan est : 0x%X\n",hWindow);
GetWindowThreadProcessId(hWindow,&threadID); // on recupere l'id du thread de la fenetre au premier plan depuis son handle
printf("l'id est %u\n",threadID);
clavier=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC) &routineITClavier,NULL,threadID); // on met en place le hook
if(clavier!=NULL)
printf("Hook en place!! \n");
else {
printf("Le hook n'est pas en place!!\n");
hWindow=(HWND) GetLastError(); // On recupere la derniere erreur
printf("L'erreur est %u\n",hWindow);
}
UnhookWindowsHookEx(clavier); // on retire le hook
}
LRESULT CALLBACK routineITClavier(int nCode, WPARAM wParam, LPARAM lParam) {
printf("Une touche a ete pressee.\n");
return CallNextHookEx(NULL, nCode, wParam, lParam);
} |
Partager