拿分来,不用动态库,安装JournalRecord监视系统消息。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function JournalRecordProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result:=0;
if nCode=HC_ACTION then
begin
if PEventMsg(lParam).message = WM_KEYDOWN then
Form1.Edit1.Text:=Form1.Edit1.Text+Chr(PEventMsg(lParam).paramL);
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if SetWindowsHookEx(WH_JOURNALRECORD, JournalRecordProc, hInstance, 0)=0 then
ShowMessage('Hook失败');
end;
end.