-
Notifications
You must be signed in to change notification settings - Fork 3
/
HIDRecord.cpp
114 lines (91 loc) · 2.5 KB
/
HIDRecord.cpp
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
#include "nilHID.h"
#include "nilUtil.h"
namespace Nil {
HIDRecord::HIDRecord( const wideString& path, HANDLE handle ):
mPath( path ), mIsXInput( false ), mIsRDP( false ), mAvailable( false )
{
HIDD_ATTRIBUTES attributes = { sizeof( HIDD_ATTRIBUTES ) };
if ( HidD_GetAttributes( handle, &attributes ) )
{
mAvailable = true;
mVendorID = attributes.VendorID;
mProductID = attributes.ProductID;
mIdentifier = MAKELONG( mVendorID, mProductID );
PHIDP_PREPARSED_DATA preparsedData;
if ( !HidD_GetPreparsedData( handle, &preparsedData ) )
NIL_EXCEPT( "HIdD_GetPreparsedData failed" );
HidP_GetCaps( preparsedData, &mCapabilities );
HidD_FreePreparsedData( preparsedData );
wchar_t buffer[256];
if ( HidD_GetProductString( handle, &buffer, 256 ) )
mName = Util::cleanupName( Util::wideToUtf8( buffer ) );
if ( HidD_GetManufacturerString( handle, &buffer, 256 ) )
mManufacturer = Util::cleanupName( Util::wideToUtf8( buffer ) );
if ( HidD_GetSerialNumberString( handle, &buffer, 256 ) )
mSerialNumber = Util::wideToUtf8( buffer );
}
identify();
}
void HIDRecord::identify()
{
if ( wcsstr( mPath.c_str(), L"ig_" ) || wcsstr( mPath.c_str(), L"IG_" ) )
{
mIsXInput = true;
}
if ( wcsstr( mPath.c_str(), L"RDP_MOU" ) || wcsstr( mPath.c_str(), L"RDP_KBD" ) )
{
mIsRDP = true;
}
}
bool HIDRecord::isAvailable() const
{
return mAvailable;
}
bool HIDRecord::isXInput() const
{
return mIsXInput;
}
bool HIDRecord::isRDP() const
{
return mIsRDP;
}
bool HIDRecord::isMicrosoft() const
{
return ( mVendorID == USBVendor_Microsoft );
}
bool HIDRecord::isLogitech() const
{
return ( mVendorID == USBVendor_Logitech );
}
uint32_t HIDRecord::getIdentifier() const
{
return mIdentifier;
}
uint16_t HIDRecord::getUsagePage() const
{
return mCapabilities.UsagePage;
}
uint16_t HIDRecord::getUsage() const
{
return mCapabilities.Usage;
}
const wideString& HIDRecord::getPath() const
{
return mPath;
}
const utf8String& HIDRecord::getManufacturer() const
{
return mManufacturer;
}
const utf8String& HIDRecord::getName() const
{
return mName;
}
const utf8String& HIDRecord::getSerialNumber() const
{
return mSerialNumber;
}
HIDRecord::~HIDRecord()
{
}
}