-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhid.ino
95 lines (89 loc) · 2.07 KB
/
hid.ino
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
#include <AsyncStream.h>
#include <Keyboard.h>
#include <AbsMouse.h>
AsyncStream<100> serial(&Serial, '\n');
void setup() {
Serial.begin(9600);
AbsMouse.init(1680, 1050);
Keyboard.begin();
serial.setEOL(';');
}
void loop() {
if (serial.available()) {
processCommand(serial.buf);
}
}
void processMouseCommand(char *command) {
int key;
int x, y;
switch (command[0]) {
case 'M':
switch (command[1]) {
case 'P': // press
key = atoi(&command[2]);
AbsMouse.press(key);
Serial.write(1);
break;
case 'R': // release
key = atoi(&command[2]);
AbsMouse.release(key);
Serial.write(1);
break;
case 'C': // click
key = atoi(&command[2]);
AbsMouse.press(key);
delay(25);
AbsMouse.release(key);
Serial.write(1);
break;
case 'V': // move
x = atoi(&command[2]);
y = atoi(strchr(&command[2], ',') + 1);
Serial.println(x);
Serial.println(y);
AbsMouse.move(x, y);
Serial.write(1);
break;
}
break;
}
}
void processKeyboardCommand(char *command) {
int key;
switch (command[0]) {
case 'K':
switch (command[1]) {
case 'P': // press
key = atoi(&command[2]);
Keyboard.press(key);
Serial.write(1);
break;
case 'R': // release
key = atoi(&command[2]);
Keyboard.release(key);
Serial.write(1);
break;
case 'W': // write
key = atoi(&command[2]);
Keyboard.write(key);
Serial.write(1);
break;
case 'T': // print
Keyboard.print(&command[2]);
Serial.write(1);
break;
}
break;
case 'R': // release all
Keyboard.releaseAll();
Serial.write(1);
break;
}
}
void processCommand(char *command) {
if (command[0] == 'M') {
processMouseCommand(command);
} else if (command[0] == 'K') {
processKeyboardCommand(command);
}
}