-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformmousevelocity.pas
58 lines (41 loc) · 1.21 KB
/
formmousevelocity.pas
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
unit FormMouseVelocity;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
type
{ TMouseVelocityForm }
TMouseVelocityForm = class(TForm)
BtnClose: TButton;
LblTitle: TLabel;
LblVelocity: TLabel;
TickTimer: TTimer;
procedure TimerTick(Sender: TObject);
private
public
DeltaX: Integer;
DeltaY: Integer;
PMouseX: Integer;
PMouseY: Integer;
end;
var
MouseVelocityForm: TMouseVelocityForm;
implementation
procedure TMouseVelocityForm.TimerTick(Sender: TObject);
var
StartTime: TDateTime;
EndTime: TDateTime;
VelocityX, VelocityY: Double;
begin
StartTime := Now;
DeltaX := Mouse.CursorPos.X - PMouseX;
DeltaY := Mouse.CursorPos.Y - PMouseY;
EndTime := Now;
VelocityX := DeltaX / (EndTime - StartTime + 1);
VelocityY := DeltaY / (EndTime - StartTime + 1);
LblVelocity.Caption := PChar(Concat('Your mouse is moving with velocity:', #13#10, FloatToStr(VelocityX), 'px/s on x-axis', #13#10, FloatToStr(VelocityY), 'px/s on y-axis'));
PMouseX := Mouse.CursorPos.X;
PMouseY := Mouse.CursorPos.Y;
end;
{$R *.lfm}
end.