summaryrefslogtreecommitdiff
path: root/fpcdocs/mouseex/logmouse.pp
blob: 9cc3acf3fd93f3310dfd4b3278a015ae456d4238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
unit logmouse;

interface

Procedure StartMouseLogging;
Procedure StopMouseLogging;
Function  IsMouseLogging : Boolean;
Procedure SetMouseLogFileName(FileName : String);


implementation

uses sysutils,Mouse;

var
  NewMouseDriver,
  OldMouseDriver : TMouseDriver;
  Active,Logging : Boolean;
  LogFileName : String;
  MouseLog : Text;

Function TimeStamp : String;

begin
  TimeStamp:=FormatDateTime('hh:nn:ss',Time());
end;

Procedure StartMouseLogging;

begin
  Logging:=True;
  Writeln(MouseLog,'Start logging mouse events at: ',TimeStamp);
end;

Procedure StopMouseLogging;

begin
  Writeln(MouseLog,'Stop logging mouse events at: ',TimeStamp);
  Logging:=False;
end;

Function IsMouseLogging : Boolean;

begin
  IsMouseLogging:=Logging;
end;

Procedure LogGetMouseEvent(Var Event : TMouseEvent);

Var
  M : TMouseEvent;

begin
  OldMouseDriver.GetMouseEvent(M);
  If Logging then
    begin
    Write(MouseLog,TimeStamp,': Mouse ');
    With M do
      begin
      Case Action of
        MouseActionDown : Write(MouseLog,'down');
        MouseActionUp   : Write(MouseLog,'up');
        MouseActionMove : Write(MouseLog,'move');
      end;
      Write(MouseLog,' event at ',X,',',Y);
      If (Buttons<>0) then
        begin
        Write(MouseLog,' for buttons: ');
        If (Buttons and MouseLeftbutton)<>0 then
          Write(MouseLog,'Left ');
        If (Buttons and MouseRightbutton)<>0 then
          Write(MouseLog,'Right ');
        If (Buttons and MouseMiddlebutton)<>0 then
          Write(MouseLog,'Middle ');
        end;
      Writeln(MouseLog);
      end;
    end;
end;

Procedure LogInitMouse;

begin
  OldMouseDriver.InitDriver();
  Assign(MouseLog,logFileName);
  Rewrite(MouseLog);
  Active:=True;
  StartMouseLogging;
end;

Procedure LogDoneMouse;

begin
  StopMouseLogging;
  Close(MouseLog);
  Active:=False;
  OldMouseDriver.DoneDriver();
end;

Procedure SetMouseLogFileName(FileName : String);

begin
  If Not Active then
    LogFileName:=FileName;
end;

Initialization
  GetMouseDriver(OldMouseDriver);
  NewMouseDriver:=OldMouseDriver;
  NewMouseDriver.GetMouseEvent:=@LogGetMouseEvent;
  NewMouseDriver.InitDriver:=@LogInitMouse;
  NewMouseDriver.DoneDriver:=@LogDoneMouse;
  LogFileName:='Mouse.log';
  Logging:=False;
  SetMouseDriver(NewMouseDriver);
end.