-
Notifications
You must be signed in to change notification settings - Fork 296
/
Copy patharduino_wifi_duck.ino
131 lines (113 loc) · 4.34 KB
/
arduino_wifi_duck.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
124
125
126
127
128
129
130
131
#include <Keyboard.h>
#define BAUD_RATE 57200
#define ExternSerial Serial1
String bufferStr = "";
String last = "";
int defaultDelay = 0;
void Line(String _line)
{
int firstSpace = _line.indexOf(" ");
if(firstSpace == -1) Press(_line);
else if(_line.substring(0,firstSpace) == "STRING"){
for(int i=firstSpace+1;i<_line.length();i++) Keyboard.write(_line[i]);
}
else if(_line.substring(0,firstSpace) == "DELAY"){
int delaytime = _line.substring(firstSpace + 1).toInt();
delay(delaytime);
}
else if(_line.substring(0,firstSpace) == "DEFAULTDELAY") defaultDelay = _line.substring(firstSpace + 1).toInt();
else if(_line.substring(0,firstSpace) == "REM"){} //nothing :/
else if(_line.substring(0,firstSpace) == "REPLAY") {
int replaynum = _line.substring(firstSpace + 1).toInt();
while(replaynum)
{
Line(last);
--replaynum;
}
} else{
String remain = _line;
while(remain.length() > 0){
int latest_space = remain.indexOf(" ");
if (latest_space == -1){
Press(remain);
remain = "";
}
else{
Press(remain.substring(0, latest_space));
remain = remain.substring(latest_space + 1);
}
delay(5);
}
}
Keyboard.releaseAll();
delay(defaultDelay);
}
void Press(String b){
if(b.length() == 1) Keyboard.press(char(b[0]));
else if (b.equals("ENTER")) Keyboard.press(KEY_RETURN);
else if (b.equals("CTRL")) Keyboard.press(KEY_LEFT_CTRL);
else if (b.equals("SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
else if (b.equals("ALT")) Keyboard.press(KEY_LEFT_ALT);
else if (b.equals("GUI")) Keyboard.press(KEY_LEFT_GUI);
else if (b.equals("UP") || b.equals("UPARROW")) Keyboard.press(KEY_UP_ARROW);
else if (b.equals("DOWN") || b.equals("DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
else if (b.equals("LEFT") || b.equals("LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
else if (b.equals("RIGHT") || b.equals("RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
else if (b.equals("DELETE")) Keyboard.press(KEY_DELETE);
else if (b.equals("PAGEUP")) Keyboard.press(KEY_PAGE_UP);
else if (b.equals("PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
else if (b.equals("HOME")) Keyboard.press(KEY_HOME);
else if (b.equals("ESC")) Keyboard.press(KEY_ESC);
else if (b.equals("BACKSPACE")) Keyboard.press(KEY_BACKSPACE);
else if (b.equals("INSERT")) Keyboard.press(KEY_INSERT);
else if (b.equals("TAB")) Keyboard.press(KEY_TAB);
else if (b.equals("END")) Keyboard.press(KEY_END);
else if (b.equals("CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
else if (b.equals("F1")) Keyboard.press(KEY_F1);
else if (b.equals("F2")) Keyboard.press(KEY_F2);
else if (b.equals("F3")) Keyboard.press(KEY_F3);
else if (b.equals("F4")) Keyboard.press(KEY_F4);
else if (b.equals("F5")) Keyboard.press(KEY_F5);
else if (b.equals("F6")) Keyboard.press(KEY_F6);
else if (b.equals("F7")) Keyboard.press(KEY_F7);
else if (b.equals("F8")) Keyboard.press(KEY_F8);
else if (b.equals("F9")) Keyboard.press(KEY_F9);
else if (b.equals("F10")) Keyboard.press(KEY_F10);
else if (b.equals("F11")) Keyboard.press(KEY_F11);
else if (b.equals("F12")) Keyboard.press(KEY_F12);
else if (b.equals("SPACE")) Keyboard.press(' ');
//else Serial.println("not found :'"+b+"'("+String(b.length())+")");
}
void setup() {
Serial.begin(BAUD_RATE);
ExternSerial.begin(BAUD_RATE);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
Keyboard.begin();
}
void loop() {
if(ExternSerial.available()) {
bufferStr = ExternSerial.readStringUntil("END");
Serial.println(bufferStr);
}
if(bufferStr.length() > 0){
bufferStr.replace("\r","\n");
bufferStr.replace("\n\n","\n");
while(bufferStr.length() > 0){
int latest_return = bufferStr.indexOf("\n");
if(latest_return == -1){
Serial.println("run: "+bufferStr);
Line(bufferStr);
bufferStr = "";
} else{
Serial.println("run: '"+bufferStr.substring(0, latest_return)+"'");
Line(bufferStr.substring(0, latest_return));
last=bufferStr.substring(0, latest_return);
bufferStr = bufferStr.substring(latest_return + 1);
}
}
bufferStr = "";
ExternSerial.write(0x99);
Serial.println("done");
}
}