unit KeyLog;
interface
uses
Vcl.Forms,
Vcl.ExtCtrls, windows, messages, SysUtils;
type
TKeyLog = class(TObject)
private
fActive: boolean;
Timer: TTimer;
Key: word;
procedure OnTimer(Sender: TObject);
procedure Process;
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
public
constructor Create;
property Active: boolean read fActive write fActive;
end;
var glbKeyLog: TKeyLog;
implementation
{ TFrameGebDatenGebaeude }
procedure TKeyLog.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if not fActive then
exit;
// Geht beides, WM_KeyDown und WM_KEYUP
// if Msg.message = WM_KeyDown then begin
if Msg.message = WM_KEYUP then begin
Key:=Msg.wParam;
Timer.Enabled := true;
end;
end;
constructor TKeyLog.Create;
begin
fActive := false;
Timer := TTimer.Create(Application);
Timer.Interval := 1;
Timer.OnTimer := OnTimer;
Timer.Enabled := false;
Application.OnMessage := AppMessage;
end;
procedure TKeyLog.OnTimer(Sender: TObject);
begin
Timer.Enabled := false;
Process;
end;
procedure TKeyLog.Process;
begin
Application.MessageBox(pwidechar('Keystroke ' + chr(Key)), '');
end;
end.