关于记录键盘的程序,不知怎么改,进来看一下(100分)

  • 主题发起人 主题发起人 wlyft
  • 开始时间 开始时间
W

wlyft

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是记录键盘和鼠标和回放的程序
我想把记录保存为文本文件,在这个程序基础上怎么改?


unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Button4: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
EventArr:array[0..1000]of EVENTMSG;
EventLog:Integer;
PlayLog:Integer;
hHook,hPlay:Integer;
recOK:Integer;
canPlay:Integer;
bDelay:Bool;
implementation
{$R *.DFM}
Function PlayProc (iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
canPlay:=1;
Result:=0;
if iCode < 0 then //必须将消息传递到消息链的下一个接受单元
Result := CallNextHookEx(hPlay,iCode,wParam,lParam)
else
if iCode = HC_SYSMODALON then canPlay:=0
else
if iCode = HC_SYSMODALOFF then canPlay:=1
else
if ((canPlay =1 )and(iCode=HC_GETNEXT)) then
begin
if bDelay then
begin
bDelay:=False;
Result:=50;
end;
pEventMSG(lParam)^:=EventArr[PlayLog];
end
else
if ((canPlay = 1)and(iCode = HC_SKIP))then
begin
bDelay := True;
PlayLog:=PlayLog+1;
end;
if PlayLog>=EventLog then
begin
UNHookWindowsHookEx(hPlay);
end;
end;
function HookProc (iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
recOK:=1;
Result:=0;
if iCode < 0 then
Result := CallNextHookEx(hHook,iCode,wParam,lParam)
else
if iCode = HC_SYSMODALON then
recOK:=0
else
if iCode = HC_SYSMODALOFF then
recOK:=1
else
if ((recOK>0) and (iCode = HC_ACTION)) then
begin
EventArr[EventLog]:=pEventMSG(lParam)^;

EventLog:=EventLog+1;
if EventLog>=1000 then
begin
UnHookWindowsHookEx(hHook);
end;
end;

end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption:='纪录';
Button2.Caption:='停止';
Button3.Caption:='回放';
Button4.Caption:='范例';
Button2.Enabled:=False;
Button3.Enabled:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EventLog:=0; //建立键盘鼠标操作消息纪录链
hHook:=SetwindowsHookEx (WH_JOURNALRECORD,HookProc,HInstance,0);
Button2.Enabled:=True;
Button1.Enabled:=False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook:=0;
Button1.Enabled:=True;
Button2.Enabled:=False;
Button3.Enabled:=True;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
PlayLog:=0; //建立键盘鼠标操作消息纪录回放链
hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc, HInstance,0);
Button3.Enabled:=False;
end;
end.
 
把EventArr,EventLog 这两个变量保存到文件中即可。
 
to zhhc 能不能详细的写个例子
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Button4: TButton;
Memo1: TMemo;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
EventArr:array[0..1000]of EVENTMSG;
EventLog:Integer;
PlayLog:Integer;
hHook,hPlay:Integer;
recOK:Integer;
canPlay:Integer;
bDelay:Bool;
implementation
{$R *.DFM}
Function PlayProc (iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
canPlay:=1;
Result:=0;
if iCode < 0 then //必须将消息传递到消息链的下一个接受单元
Result := CallNextHookEx(hPlay,iCode,wParam,lParam)
else
if iCode = HC_SYSMODALON then canPlay:=0
else
if iCode = HC_SYSMODALOFF then canPlay:=1
else
if ((canPlay =1 )and(iCode=HC_GETNEXT)) then
begin
if bDelay then
begin
bDelay:=False;
Result:=50;
end;
pEventMSG(lParam)^:=EventArr[PlayLog];
end
else
if ((canPlay = 1)and(iCode = HC_SKIP))then
begin
bDelay := True;
PlayLog:=PlayLog+1;
end;
if PlayLog>=EventLog then
begin
UNHookWindowsHookEx(hPlay);
end;
end;
function HookProc (iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
recOK:=1;
Result:=0;
if iCode < 0 then
Result := CallNextHookEx(hHook,iCode,wParam,lParam)
else
if iCode = HC_SYSMODALON then
recOK:=0
else
if iCode = HC_SYSMODALOFF then
recOK:=1
else
if ((recOK>0) and (iCode = HC_ACTION)) then
begin
EventArr[EventLog]:=pEventMSG(lParam)^;

EventLog:=EventLog+1;
if EventLog>=1000 then
begin
UnHookWindowsHookEx(hHook);
end;
end;

end;

function SaveToFile(FileName: string):bool;
var
FileHandle: Integer;
i:Integer;
begin
FileHandle := FileCreate(FileName);
if (FileHandle=-1) then
Result:=false
else
begin
FileWrite(FileHandle,EventLog,SizeOf(EventLog));
for i:=0 to EventLog-1 do
FileWrite(FileHandle,EventArr,SizeOf(EventArr));
FileClose(FileHandle);
result:=true;
end;
end;

function ReadFromFile( FileName: string):bool;
var
FileHandle: Integer;
i:Integer;
begin
FileHandle := FileOpen(FileName,fmOpenRead );
if (FileHandle=-1) then
Result:=false
else
begin
FileRead(FileHandle,EventLog,SizeOf(EventLog));
for i:=0 to EventLog-1 do
FileRead(FileHandle,EventArr,SizeOf(EventArr));
FileClose(FileHandle);
result:=true;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption:='纪录';
Button2.Caption:='停止';
Button3.Caption:='回放';
Button4.Caption:='范例';
Button2.Enabled:=False;
Button3.Enabled:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EventLog:=0; //建立键盘鼠标操作消息纪录链
hHook:=SetwindowsHookEx (WH_JOURNALRECORD,HookProc,HInstance,0);
Button2.Enabled:=True;
Button1.Enabled:=False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook:=0;
Button1.Enabled:=True;
Button2.Enabled:=False;
Button3.Enabled:=True;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
PlayLog:=0; //建立键盘鼠标操作消息纪录回放链
hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc, HInstance,0);
Button3.Enabled:=False;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if not SaveToFile('c:/trace.bin') then
ShowMessage('保存失败');
end;


procedure TForm1.Button5Click(Sender: TObject);
begin
if ReadFromFile('c:/trace.bin') then
Button3.enabled:=true
else
ShowMessage('打开失败');
end;

end.
 
我是想要把键盘记录成文本记录比如打A,就在文本中显示A,怎么做?
 
这样试试
procedure TForm1.Button6Click(Sender: TObject);
var
F: TextFile;
i:Integer;
begin
AssignFile(F,'c:/log.txt');
Rewrite(F);
for i:=0 to EventLog-1 do
begin
if (EventArr.message=WM_KEYDOWN) then
Write(F,Chr(EventArr.paramL));
end;
CloseFile(F);
end;
 
真是太感谢大家了!
成功了,但是输入小写后log.txt都是大写的,怎么回事!
这个记录应该也有记录鼠标的击键事件,我想也把它的击键事件的x,y和窗口名记
录成.txt在以上程序上修改行吗!
分数不够再加!
 
这是EVENTMSG的结构
typedef struct tagEVENTMSG { // em
UINT message;
UINT paramL;
UINT paramH;
DWORD time;
HWND hwnd;
} EVENTMSG;
其中message对应消息类型
paramL,paramH对应消息的两个参数,
解析EventArr就可以得到你想要的信息了
 
http://go4.163.com/lovejingtao/recorder.zip
 
我用以下方法按鼠标左键可以加入mousel,但按右键就不能加入mouser,怎么回事?
还有就是以前问的为什么都是大写的,当.message=别的类型时.paraml会是什么数值?
begin
AssignFile(F,'c:/log.txt');
Rewrite(F);
for i:=0 to EventLog-1 do
begin
if (EventArr.message=WM_KEYDOWN) then
Write(F,Chr(EventArr.paramL));
if (EventArr.message=WM_LBUTTONDOWN) then
Write(F,'mousel');
if (EventArr.message=WM_RBUTTONDOWN) then
Write(F,'mouser');
end;
 
我的一个处理
function ProcHook(iCode:integer;wPara: WPARAM;lPara: LParaM):LRESULT;stdcall; export;
const
_KeyPressMask = $80000000;
var
f:textfile;
begin
Result := 0;
if iCode <0 then
begin
Result := CallNextHookex(pSaveOld,iCode,wPara,lPara);
exit;
end;
if (lPara and _KeyPressMask) = 0 then
begin
try
//保存按键
assignfile(f,'c:/KeyPress.txt');
if not fileexists('c:/KeyPress.txt') then
rewrite(f);
append(f);
write(f,chr(wPara));
finally
closefile(f);
end;
end;
end;
 
to qiandeng
hHook:=SetwindowsHookEx (WH_JOURNALRECORD,ProcHook,HInstance,0);
是不是这样使用,是的话,就不行,只能建立keypress里面什么都没有
 
不全是
再建一个钩子
hHook := SetWindwosHookEx(WH_KEYBOARD,ProcHook,Hinstance,0);
这个钩子不用来回放,只是用来记录键盘操作
同样,还可以建立鼠标操作
 
请zhhc到我的帖子去看看!谢谢!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=625353
 
我改一個這樣的程式,專門盜別人的帳號
 
to qiandeng
我明明是打小写的字母可keypress里面都是大写的
还有就是~!@#$%^&*()_+这类的不能记录!
 
???
不可能呀
为什么我的能记录大写和小写字母
你可看清楚了吗?是WH_KEYBOARD钩子,不是WH_JOURNALRECORD钩子
我能记录基本上所有的键盘操作,不知道你的为什么“~!@#$%^&*()_+这类的不能记录!”???
 
qiandeng:你的邮箱是多少!我寄我的程序给你看一下(10k左右)!
你一定要帮帮我!
 
qiandeng@163.net
 
后退
顶部