-
Notifications
You must be signed in to change notification settings - Fork 0
/
microkeyboard.ino
123 lines (104 loc) · 2.82 KB
/
microkeyboard.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
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
#include <Keyboard.h>
void setup() {
Serial1.begin(115200);
while (!Serial1)
{
; // wait for serial port to connect. Needed for Leonardo only
}
// initialize control over the keyboard:
Keyboard.begin();
Serial1.println("Starting\n");
usage();
}
void usage() {
Serial1.println("Select mode:");
Serial1.println("s - single: enter a single key to be sent");
Serial1.println("b - loop: loop over the function keys + 0x00-0xff combos");
Serial1.println("k - loop: loop over all single key presses");
}
void brute_special_combos() {
Serial1.println("Starting brute force loop of special key combos. Press SPACE to stop");
//roll through the modifier keys with every combo
for(int fkey=0x80;fkey < 0xFB;fkey++){
for(int skey=0x00;skey<256;skey++){
delay(1000);
Serial1.println("Trying: " + String(fkey) + " + " + String(skey));
Keyboard.press(fkey);
Keyboard.press(skey);
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(500);
int check = Serial1.read();
if(check == 32){
Serial1.println("Aborting run");
usage();
return;
}
}
}
}
void brute_singles() {
Serial1.println("Starting brute force loop of single keys. Press SPACE to stop");
//roll through the modifier keys with every combo
for(int skey=0x00;skey<256;skey++){
delay(1000);
Serial1.println("Trying: " + String(skey));
// Keyboard.press('');
Keyboard.press(skey);
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(500);
int check = Serial1.read();
if(check == 32){
Serial1.println("Aborting run");
usage();
return;
}
}
}
void single() {
Serial1.println("Starting single mode.");
Serial1.println("Every key typed will be send to the target. ESC ESC ESC ESC to stop.");
int stop_sum = 0;
int prev_key = 0;
while(true){
int key = -1;
key = Serial1.read();
if(key != -1) {
Serial1.println("Sending: " + String(key));
if(key == 27 && prev_key == 27){
stop_sum += 27;
if(stop_sum == 81){
Serial1.println("Aborting run");
usage();
return;
}
}
Keyboard.write(key);
prev_key = key;
}
// delay(1000);
// Serial1.println(String(key));
}
}
void loop() {
int choice = -1;
while(choice == -1){
choice = Serial1.read();
switch (char(choice)) {
case 's':
single();
break;
case 'b':
brute_special_combos();
break;
case 'k':
brute_singles();
break;
default:
break;
}
}
}