-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClickRecorder.MainForm.pas
More file actions
145 lines (127 loc) · 3.23 KB
/
ClickRecorder.MainForm.pas
File metadata and controls
145 lines (127 loc) · 3.23 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
unit ClickRecorder.MainForm;
interface
uses
Winapi.Windows,
// Winapi.Messages,
System.SysUtils,
System.Classes,
System.ClickRecorder.Factory,
Vcl.Graphics,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.Controls,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
BtnStart: TButton;
BtnStop: TButton;
BtnScreenshot: TButton;
BtnPainting: TButton;
Timer1: TTimer;
procedure BtnStartClick(Sender: TObject);
procedure BtnStopClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BtnScreenshotClick(Sender: TObject);
procedure BtnPaintingClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
FInnerClickRecorderFactory: IClickRecorderFactory;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
uses
{$IFDEF MSWINDOWS}
Vcl.Clipbrd,
{$ENDIF}
{$IFDEF MACOS}
FMX.Clipbrd,
{$ENDIF}
System.IOUtils;
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if FInnerClickRecorderFactory.IsRecording then
begin
ShowMessage('Please, stop recording, befor closing the application.');
Action := caNone;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FInnerClickRecorderFactory := TClickRecorderFactory.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FInnerClickRecorderFactory.Stop;
FInnerClickRecorderFactory := nil;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Caption := Format('Click Recoding x:%d - y:%d', [Mouse.CursorPos.X, Mouse.CursorPos.Y]);
end;
procedure TForm1.BtnStartClick(Sender: TObject);
begin
var AppParamValueOutDir: string := string.Empty;
if (FindCmdLineSwitch('OUTDIR:', AppParamValueOutDir)) then
begin
if (not TDirectory.Exists(AppParamValueOutDir)) then
begin
TDirectory.CreateDirectory(AppParamValueOutDir);
end;
end
else
AppParamValueOutDir := TPath.GetAppPath;
FInnerClickRecorderFactory
.OutDir(AppParamValueOutDir)
.Start;
end;
procedure TForm1.BtnStopClick(Sender: TObject);
begin
FInnerClickRecorderFactory.Stop;
end;
procedure TForm1.BtnScreenshotClick(Sender: TObject);
var
BMP: TBitmap;
begin
// Windows.GetCursorPos(CursorPoint);
// Mouse.CursorPos := Self.ClientToScreen(CursorPoint);
// Self.ScreenToClient
BMP := FInnerClickRecorderFactory
.ScreenshotProvider
.TakeAScreenshot(Mouse.CursorPos);
try
ClipBoard.Assign(BMP);
finally
BMP.Free;
BMP := nil;
end;
end;
procedure TForm1.BtnPaintingClick(Sender: TObject);
var
x,y: Integer;
Bitmap: TBitmap;
P: PByteArray;
begin
// https://docwiki.embarcadero.com/RADStudio/Florence/de/In_Bitmaps_zeichnen
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('C:\temp\any.bmp');
for y := 0 to Bitmap.height - 1 do
begin
P := Bitmap.ScanLine[y];
for x := 0 to Bitmap.width - 1 do
P[x] := y;
end;
canvas.draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
end;
end.