-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRawInputCommon.pas
154 lines (122 loc) · 5.52 KB
/
RawInputCommon.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
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
146
147
148
149
150
151
152
153
154
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
RawInput managing library
Common material and classes
©František Milt 2018-10-22
Version 0.9.3
Dependencies:
AuxTypes - github.com/ncs-sniper/Lib.AuxTypes
AuxClasses - github.com/ncs-sniper/Lib.AuxClasses
BitOps - github.com/ncs-sniper/Lib.BitOps
MulticastEvent - github.com/ncs-sniper/Lib.MulticastEvent
WndAlloc - github.com/ncs-sniper/Lib.WndAlloc
WinRawInput - github.com/ncs-sniper/Lib.WinRawInput
BitVector - github.com/ncs-sniper/Lib.BitVector
UtilityWindow - github.com/ncs-sniper/Lib.UtilityWindow
DefRegistry - github.com/ncs-sniper/Lib.DefRegistry
StrRect - github.com/ncs-sniper/Lib.StrRect
* SimpleCPUID - github.com/ncs-sniper/Lib.SimpleCPUID
SimpleCPUID might not be needed, see BitOps library for details.
===============================================================================}
unit RawInputCommon;
{$INCLUDE 'RawInput_defs.inc'}
interface
uses
Windows, Classes,
AuxClasses, WinRawInput;
type
TPreparsedData = array of Byte;
TAdditionalInfo = record
Description: String;
Manufacturer: String;
DeviceClass: String;
ClassGUID: TGUID;
end;
TDeviceListItem = record
Handle: THandle;
Name: String;
Info: RID_DEVICE_INFO;
PreparsedData: TPreparsedData;
AdditionalInfo: TAdditionalInfo;
end;
PDeviceListItem = ^TDeviceListItem;
TDeviceList = array of TDeviceListItem;
PDeviceList = ^TDeviceList;
TRegisteredDevicesList = array of TRawInputDevice;
PRegisteredDevicesList = ^TRegisteredDevicesList;
TRawInputEvent = procedure(Sender: TObject; Data: Pointer; Size: UINT) of object;
TUnknownDeviceEvent = procedure(Sender: TObject; DeviceHandle: THandle) of object;
{==============================================================================}
{------------------------------------------------------------------------------}
{ TRawInputProcessingObject }
{------------------------------------------------------------------------------}
{==============================================================================}
{==============================================================================}
{ TRawInputProcessingObject - declaration }
{==============================================================================}
TRawInputProcessingObject = class(TCustomObject)
private
fActive: Boolean;
fDeviceInfo: TDeviceListItem;
fIndex: Integer;
fTag: Integer;
fUserData: Pointer;
fOnRawInput: TRawInputEvent;
fOnDestroy: TNotifyEvent;
protected
procedure ProcessRawInputSpecific(RawInput: PRawInput); virtual; abstract;
public
constructor Create(DeviceInfo: PDeviceListItem = nil);
destructor Destroy; override;
procedure ProcessRawInput(RawInput: PRawInput); virtual;
procedure Invalidate; virtual; abstract;
property UserData: Pointer read fUserData write fUserData;
property DeviceInfo: TDeviceListItem read fDeviceInfo;
property Active: Boolean read fActive write fActive;
property Index: Integer read fIndex write fIndex;
property Tag: Integer read fTag write fTag;
property OnRawInput: TRawInputEvent read fOnRawInput write fOnRawInput;
property OnDestroy: TNotifyEvent read fOnDestroy write fOnDestroy;
end;
implementation
{==============================================================================}
{------------------------------------------------------------------------------}
{ TRawInputProcessingObject }
{------------------------------------------------------------------------------}
{==============================================================================}
{==============================================================================}
{ TRawInputProcessingObject - implementation }
{==============================================================================}
{------------------------------------------------------------------------------}
{ TRawInputProcessingObject - public methods }
{------------------------------------------------------------------------------}
constructor TRawInputProcessingObject.Create(DeviceInfo: PDeviceListItem = nil);
begin
inherited Create;
fActive := True;
If Assigned(DeviceInfo) then
fDeviceInfo := DeviceInfo^
else
FillChar(fDeviceInfo,SizeOf(TDeviceListItem),0);
fIndex := -1;
end;
//------------------------------------------------------------------------------
destructor TRawInputProcessingObject.Destroy;
begin
If Assigned(fOnDestroy) then fOnDestroy(Self);
inherited;
end;
//------------------------------------------------------------------------------
procedure TRawInputProcessingObject.ProcessRawInput(RawInput: PRawInput);
begin
If fActive then
begin
If Assigned(fOnRawInput) then fOnRawInput(Self,RawInput,RawInput^.header.dwSize);
ProcessRawInputSpecific(RawInput);
end;
end;
end.