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 53
| void hookClavier() {
HWND hWindow;
DWORD threadID;
HHOOK clavier;
DWORD processID;
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);
processID=GetWindowThreadProcessId(hWindow,&threadID); // on recupere l'id du thread et du processus de la fenetre au premier plan depuis son handle
printf("l'id est %u\n",threadID);
printf("l'id est %u\n",processID);
clavier=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC) &routineITClavier,NULL,processID); // 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);
}
process1();
UnhookWindowsHookEx(clavier); // on retire le hook
}
LRESULT CALLBACK routineITClavier(int nCode, WPARAM wParam, LPARAM lParam) {
printf("Une touche a ete pressee.\n");
exit(-1);
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
void process1() {
int i=0;
while(i<99999999999) {
if(i%54000==0)
printf("%d ",i);
i++;
}
} |
Partager