hook
2023-08-08 17:09:58
发布于:浙江
#include<Windows.h>
#include<cstdio>
//#include<cstring>
//int p[] = {186,8,13,46,32,9,-1};
SYSTEMTIME systime;
LRESULT CALLBACK Proc(int code,WPARAM w,LPARAM l) {
KBDLLHOOKSTRUCT *T=(KBDLLHOOKSTRUCT*)l;
DWORD x=T->vkCode;
if(w==WM_KEYDOWN&&code == HC_ACTION) {
GetLocalTime(&systime);
printf("Tip->%d/%d/%d %d:%d:%d",systime.wYear
,systime.wMonth
,systime.wDay
,systime.wHour
,systime.wMinute
,systime.wSecond);
printf(" Press: %d",(int)x);
if((int)x == 119) {
PostQuitMessage(0);
}
//putchar(x);
putchar('\n');
// for(int i = 0;p[i] != -1;i++){
// if((int)x == p[i]){
// CallNextHookEx(NULL,code,w,l);
// return 1;
// }
// }
if((int)x >= 65 && (int)x <= 90&&((KBDLLHOOKSTRUCT*)l)->dwExtraInfo != 1) {
keybd_event(((int)x - 64) % 26 + 65, MapVirtualKey(((int)x - 64) % 26 + 65, 0), 0, 1);
CallNextHookEx(NULL,code,w,l);
return 1;
} else {
CallNextHookEx(NULL,code,w,l);
return 0;
}
return 1;
} else {
return CallNextHookEx(NULL,code,w,l);
}
return CallNextHookEx(NULL,code,w,l);
}
int main() {
//freopen("Date.in","a+",stdout);
HHOOK hook=::SetWindowsHookEx(WH_KEYBOARD_LL,Proc,0,0);
MSG msg;
while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(hook);
return 0;
}
这里空空如也
有帮助,赞一个