-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
139 lines (105 loc) · 2.82 KB
/
main.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
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
#include <stdio.h>
#include <string.h>
struct Client
{
bool connected;
char buffer[64];
int bufferPosition;
};
Client clients[8];
bool hasCommand(char* cmd);
bool ProcessCmd(char* cmd);
bool ProcessLocalCmd(char* device, char* action);
bool ProcessKeyboardCommand(int modifiers, int key);
int main()
{
// Cmd: USB1_KBD_A
// USB KBD/MOUSE
// 0 = local
// 1 = i2c device #1
// 2 = i2c device #2
// Bluetooth KBD/MOUSE
// 1 = (default)
// ALT+F4?
// Modifiers_KEY _KEYBD
strcpy(clients[0].buffer, "USB1_KEYBD_LCTRL+LALT_F4\r");
ProcessCmd(strupr(clients[0].buffer));
getchar();
return 0;
}
bool ProcessCmd(char* cmd)
{
// valid targets: USB#, BTH#
char* target = strtok(cmd, "_");
if (!target)
return false;
// valid devices, KEYBD, MOUSE
char* device = strtok(NULL, "_");
if (!device)
return false;
char* action = strtok(NULL, "\r");
if (!action)
return false;
printf("Target: [%s], device: [%s], action: [%s]", target, device, action);
// or strcasecmp
if (stricmp(target, "USB1") == 0)
ProcessLocalCmd(device, action);
return false;
}
/*
Binary Input Function
0 Disconnect if connected from the host.
0x1 - 0xF Converted to special keys like home, page up, backspace, etc.
0x10 - 0x7E Translation mode: printable ASCII characters.
0x7F Toggle virtual keyboard on iPhone.
0x80 - 0xDF Interprets input as actual scan code.
0xE0 - 0xE7 Sends modifier keys Left Shift, Left Alt, Right Shift, etc.
0xE8 - 0xEF Interprets input as actual scan code.
0xF0 - 0xFC Reserved for custom reports.
0xFD Raw mode: input is RAW report.
0xFE Interpretive mode: input is shorthand report.
0xFF Sends output report to UART.
*/
bool ProcessLocalCmd(char* device, char* action)
{
if (stricmp(device, "KEYBD") == 0)
{
// valid modifiers: RGUI, RALT, RSHIFT, RCTRL,
// LGUI, LALT, LSHIFT, LCTRL
char* modifiers = strtok(action, "_");
if (!modifiers)
return false;
char* keyCode = strtok(NULL, "\r");
if (!keyCode)
return false;
int mod = 0;
if (strstr(modifiers, "RGUI"))
mod = mod | 0x80;
if (strstr(modifiers, "RALT"))
mod = mod | 0x40;
if (strstr(modifiers, "RSHIFT"))
mod = mod | 0x20;
if (strstr(modifiers, "RCTRL"))
mod = mod | 0x10;
if (strstr(modifiers, "LGUI"))
mod = mod | 0x8;
if (strstr(modifiers, "LALT"))
mod = mod | 0x4;
if (strstr(modifiers, "LSHIFT"))
mod = mod | 0x2;
if (strstr(modifiers, "LCTRL"))
mod = mod | 0x1;
return ProcessKeyboardCommand(mod, (int)*action);
}
return true;
}
bool ProcessKeyboardCommand(int modifiers, int key)
{
// check for printable ASCII character
// 32 = 0x20
// 126 = 0x7E
if (key >= 32 && key <= 126)
{
}
return false;
}