-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.pas
81 lines (68 loc) · 1.46 KB
/
Main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
unit Main;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls;
type
TForm9 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
FPrevious: string;
function GetButtonStatus: string;
end;
var
Form9: TForm9;
implementation
uses
Winapi.MMSystem, System.IOUtils;
{$R *.dfm}
procedure TForm9.FormCreate(Sender: TObject);
begin
Memo1.Clear;
end;
procedure TForm9.Timer1Timer(Sender: TObject);
var
Current: string;
LogLine: string;
begin
Current := GetButtonStatus;
if FPrevious <> Current then
begin
FPrevious := Current;
LogLine := DateTimeToStr(Now) + ' - ' + Current;
Memo1.Lines.Add(LogLine);
TFile.AppendAllText('joystick.log', LogLine + sLineBreak);
end;
end;
function TForm9.GetButtonStatus: string;
var
MyJoy: TJoyInfo;
ErrorResult: MMRESULT;
begin
ErrorResult := joyGetPos(JOYSTICKID1, @MyJoy);
if ErrorResult <> JOYERR_NOERROR then
Exit('ERROR ' + IntToStr(ErrorResult));
Result := 'Button 1: ';
if ((MyJoy.wButtons and joy_button1) > 0) then
Result := Result + 'ON'
else
Result := Result + 'OFF';
Result := Result + ' Button 2: ';
if ((MyJoy.wButtons and joy_button2) > 0) then
Result := Result + 'ON'
else
Result := Result + 'OFF';
end;
end.