-
Notifications
You must be signed in to change notification settings - Fork 0
/
HidCtrl.h
151 lines (123 loc) · 2.32 KB
/
HidCtrl.h
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
#pragma once
#include <windows.h>
#include <string>
#include <vector>
#include <set>
#include <Setupapi.h>
#include <assert.h>
extern "C"
{
#include "hidsdi.h"
#include "hidpi.h"
}
using namespace std;
const int KEY_DEFINE_LENGTH = 128;
enum{
SENSOR_INVAILD = -1,
SENSOR_ADNS3050 = 0,
SENSOR_ADNS5050,
SENSOR_ADNS3000,
};
enum{
MODE_KEY = 0x0, //键盘组合
MODE_MOUSE = 0x1, //鼠标按键
MODE_MEDIA = 0x3, //多媒体键
MODE_DPI = 0x7, //DPI 键功能
MODE_DEFINE = 0x9, //宏定义
MODE_HIT_KEY = 0xa, //连击键键码连
MODE_LED_ONOFF = 0xc,//灯光开关
MODE_DISABLE = 0xf,
};
#pragma pack(push)
#pragma pack(1)
struct HdiMousePara
{
HdiMousePara()
{
memset(value,0,sizeof(value));
}
union
{
BYTE value[64];
struct
{
BYTE CPI[8];
BYTE CPIColor[8][3];
BYTE Color[4]; //字节为设定鼠标颜色R、G、B、W(取值为0)
BYTE LedMode; //00 常亮模式 01 呼吸模式 02 光谱模式 03 APM 模式
BYTE LedSpeed; //1~32
};
};
};
struct HdiMouseMap
{
HdiMouseMap()
{
memset(value,0,sizeof(value));
}
union
{
BYTE value[64];
struct //映射表
{
BYTE keyMap[16][4];
};
};
};
struct HdiMouseDefine
{
struct keyComp
{
keyComp()
{
type = 0;
keyHid = 0;
time = 0;
}
int type; //0 down,1 up
int keyHid; //hid
int time;
};
HdiMouseDefine();
void Clear();
int ToBuffer(BYTE *buffer) const;
bool FromBuffer(const BYTE *buffer);
void StartRecord(bool delay);
bool AddKey(int code,int type);
void StopRecord();
bool CheckSpace();
bool IsAutoDelay();
int repeat;
vector<keyComp> keyList;
private:
set<int> needUpKey();
bool mRecord;
bool mAutoDelay;
int oldTick;
};
#pragma pack(pop)
class CHidCtrl
{
public:
CHidCtrl(void);
~CHidCtrl(void);
bool GetDevice(bool isCheck);
bool CheckDevice();
bool Init();
void DeInit();
bool SetPara(const HdiMousePara ¶);
bool GetPara(int &sensor_type,int &mouse_id,HdiMousePara ¶);
bool SetMap(const HdiMouseMap ¶);
bool GetMap(HdiMouseMap ¶);
bool SetDefine(int seq,const HdiMouseDefine ¶);
bool GetDefine(int seq,HdiMouseDefine ¶);
bool SetFinish();
bool SetLedReportGap(int gap);
bool SetLedOnOff(bool on);
string GetError();
private:
bool ReadInData(BYTE *buffer,int time);
HANDLE mHandleIn;
HANDLE mHandleOut;
string mError;
};