@@ -59,25 +59,26 @@ bool transpiler::checkArgs(const std::vector<String>& args, const uint8_t expect
59
59
}
60
60
61
61
void transpiler::processLine (const char * command, const std::vector<String>& args) {
62
- if (strcmp (command, " write" ) == 0 ) { // write "<text>"
63
- Serial.println ( " write" );
62
+ if (strcmp (command, " write" ) == 0 ) {
64
63
if (!checkArgs (args, 1 )) return ;
64
+
65
65
Keyboard.print (args[0 ]);
66
66
}
67
67
68
- if (strcmp (command, " writeLn" ) == 0 ) { // writeLn "<text>"
68
+ if (strcmp (command, " writeLn" ) == 0 ) {
69
69
if (!checkArgs (args, 1 )) return ;
70
+
70
71
Keyboard.print (args[0 ]);
71
72
Keyboard.press (KEY_RETURN);
72
73
Keyboard.release (KEY_RETURN);
73
74
}
74
75
75
- if (strcmp (command, " delay" ) == 0 ) { // delay "<integer>"
76
+ if (strcmp (command, " delay" ) == 0 ) {
76
77
if (!checkArgs (args, 1 )) return ;
77
78
delay (args[0 ].toInt ());
78
79
}
79
80
80
- if (strcmp (command, " terminal" ) == 0 ) { // terminal "<operating_system>"
81
+ if (strcmp (command, " terminal" ) == 0 ) {
81
82
if (!checkArgs (args, 1 )) return ;
82
83
if (args[0 ] == " windows" ) {
83
84
Keyboard.press (KEY_LEFT_GUI);
@@ -107,88 +108,25 @@ void transpiler::processLine(const char* command, const std::vector<String>& arg
107
108
}
108
109
}
109
110
110
- if (strcmp (command, " winShutdown" ) == 0 )
111
- {
112
- Keyboard.press (KEY_LEFT_GUI);
113
- Keyboard.press (' X' );
114
- Keyboard.releaseAll ();
115
-
116
- delay (1000 );
117
-
118
- Keyboard.press (' U' );
119
- Keyboard.releaseAll ();
120
-
121
- Keyboard.press (' U' );
122
- Keyboard.releaseAll ();
123
- }
124
-
125
- if (strcmp (command, " key" ) == 0 )
126
- {
111
+ if (strcmp (command, " key" ) == 0 ) {
127
112
if (!checkArgs (args, 1 )) return ;
128
113
129
- if (args[0 ] == " enter" ) Keyboard.press (KEY_RETURN);
130
- else if (args[0 ] == " esc" ) Keyboard.press (KEY_ESC);
131
- else if (args[0 ] == " backspace" ) Keyboard.press (KEY_BACKSPACE);
132
- else if (args[0 ] == " tab" ) Keyboard.press (KEY_TAB);
133
- else if (args[0 ] == " space" ) Keyboard.press (' ' );
134
- else if (args[0 ] == " delete" ) Keyboard.press (KEY_DELETE);
135
- else if (args[0 ] == " insert" ) Keyboard.press (KEY_INSERT);
136
- else if (args[0 ] == " home" ) Keyboard.press (KEY_HOME);
137
- else if (args[0 ] == " end" ) Keyboard.press (KEY_END);
138
- else if (args[0 ] == " pageup" ) Keyboard.press (KEY_PAGE_UP);
139
- else if (args[0 ] == " pagedown" ) Keyboard.press (KEY_PAGE_DOWN);
140
- else if (args[0 ] == " up" ) Keyboard.press (KEY_UP_ARROW);
141
- else if (args[0 ] == " down" ) Keyboard.press (KEY_DOWN_ARROW);
142
- else if (args[0 ] == " left" ) Keyboard.press (KEY_LEFT_ARROW);
143
- else if (args[0 ] == " right" ) Keyboard.press (KEY_RIGHT_ARROW);
144
- else if (args[0 ] == " ctrl" ) Keyboard.press (KEY_LEFT_CTRL);
145
- else if (args[0 ] == " shift" ) Keyboard.press (KEY_LEFT_SHIFT);
146
- else if (args[0 ] == " alt" ) Keyboard.press (KEY_LEFT_ALT);
147
- else if (args[0 ] == " gui" ) Keyboard.press (KEY_LEFT_GUI);
148
- else if (args[0 ] == " capslock" ) Keyboard.press (KEY_CAPS_LOCK);
149
- else if (args[0 ] == " numlock" ) Keyboard.press (KEY_NUM_LOCK);
150
- else if (args[0 ] == " prtsc" ) Keyboard.press (KEY_PRINT_SCREEN);
151
- else if (args[0 ] == " scrolllock" ) Keyboard.press (KEY_SCROLL_LOCK);
152
- else if (args[0 ] == " pause" ) Keyboard.press (KEY_PAUSE);
153
- else return ;
114
+ pressKey (args[0 ]);
154
115
155
116
Keyboard.releaseAll ();
156
117
}
157
118
158
- if (strcmp (command, " functionKey" ) == 0 ) // functionKey "<F1-F24>"
159
- {
119
+ if (strcmp (command, " comboKey" ) == 0 ) {
160
120
if (!checkArgs (args, 1 )) return ;
161
- if (args[0 ] == " F1" ) Keyboard.press (KEY_F1);
162
- else if (args[0 ] == " F2" ) Keyboard.press (KEY_F2);
163
- else if (args[0 ] == " F3" ) Keyboard.press (KEY_F3);
164
- else if (args[0 ] == " F4" ) Keyboard.press (KEY_F4);
165
- else if (args[0 ] == " F5" ) Keyboard.press (KEY_F5);
166
- else if (args[0 ] == " F6" ) Keyboard.press (KEY_F6);
167
- else if (args[0 ] == " F7" ) Keyboard.press (KEY_F7);
168
- else if (args[0 ] == " F8" ) Keyboard.press (KEY_F8);
169
- else if (args[0 ] == " F9" ) Keyboard.press (KEY_F9);
170
- else if (args[0 ] == " F10" ) Keyboard.press (KEY_F10);
171
- else if (args[0 ] == " F11" ) Keyboard.press (KEY_F11);
172
- else if (args[0 ] == " F12" ) Keyboard.press (KEY_F12);
173
- else if (args[0 ] == " F13" ) Keyboard.press (KEY_F13);
174
- else if (args[0 ] == " F14" ) Keyboard.press (KEY_F14);
175
- else if (args[0 ] == " F15" ) Keyboard.press (KEY_F15);
176
- else if (args[0 ] == " F16" ) Keyboard.press (KEY_F16);
177
- else if (args[0 ] == " F17" ) Keyboard.press (KEY_F17);
178
- else if (args[0 ] == " F18" ) Keyboard.press (KEY_F18);
179
- else if (args[0 ] == " F19" ) Keyboard.press (KEY_F19);
180
- else if (args[0 ] == " F20" ) Keyboard.press (KEY_F20);
181
- else if (args[0 ] == " F21" ) Keyboard.press (KEY_F21);
182
- else if (args[0 ] == " F22" ) Keyboard.press (KEY_F22);
183
- else if (args[0 ] == " F23" ) Keyboard.press (KEY_F23);
184
- else if (args[0 ] == " F24" ) Keyboard.press (KEY_F24);
185
- else return ;
186
121
122
+ std::vector<String> keys = split (args[0 ], ' +' );
123
+ for (const String& key : keys) {
124
+ pressKey (key);
125
+ }
187
126
Keyboard.releaseAll ();
188
127
}
189
128
190
- if (strcmp (command, " arrowKey" ) == 0 ) // arrowKey "<up/down/left/right>"
191
- {
129
+ if (strcmp (command, " arrowKey" ) == 0 ) {
192
130
if (!checkArgs (args, 1 )) return ;
193
131
if (args[0 ] == " up" ) Keyboard.press (KEY_UP_ARROW);
194
132
else if (args[0 ] == " down" ) Keyboard.press (KEY_DOWN_ARROW);
@@ -199,19 +137,6 @@ void transpiler::processLine(const char* command, const std::vector<String>& arg
199
137
Keyboard.releaseAll ();
200
138
}
201
139
202
- if (strcmp (command, " clipboard" ) == 0 ) {
203
- if (!checkArgs (args, 1 )) return ;
204
- if (args[0 ] == " copy" ) {
205
- Keyboard.press (KEY_LEFT_CTRL);
206
- Keyboard.press (' c' );
207
- Keyboard.releaseAll ();
208
- } else if (args[0 ] == " paste" ) {
209
- Keyboard.press (KEY_LEFT_CTRL);
210
- Keyboard.press (' v' );
211
- Keyboard.releaseAll ();
212
- }
213
- }
214
-
215
140
if (strcmp (command, " keyboardLayout" ) == 0 )
216
141
{
217
142
if (!checkArgs (args, 1 )) return ;
@@ -238,3 +163,57 @@ void transpiler::processLine(const char* command, const std::vector<String>& arg
238
163
}
239
164
}
240
165
166
+ std::vector<String> transpiler::split (const String& str, const char delimiter) {
167
+ std::vector<String> tokens;
168
+ String token = " " ;
169
+
170
+ for (size_t i = 0 ; i < str.length (); i++) {
171
+ if (str[i] == delimiter) {
172
+ if (token.length () > 0 ) {
173
+ tokens.push_back (token);
174
+ token = " " ;
175
+ }
176
+ } else {
177
+ token += str[i];
178
+ }
179
+ }
180
+ if (token.length () > 0 ) {
181
+ tokens.push_back (token);
182
+ }
183
+ return tokens;
184
+ }
185
+
186
+ void transpiler::pressKey (const String& key) {
187
+ if (key == " enter" ) Keyboard.press (KEY_RETURN);
188
+ else if (key == " esc" ) Keyboard.press (KEY_ESC);
189
+ else if (key == " backspace" ) Keyboard.print (" " );
190
+ else if (key == " tab" ) Keyboard.press (KEY_TAB);
191
+ else if (key == " space" ) Keyboard.press (KEY_BACKSPACE);
192
+ else if (key == " delete" ) Keyboard.press (KEY_DELETE);
193
+ else if (key == " insert" ) Keyboard.press (KEY_INSERT);
194
+ else if (key == " home" ) Keyboard.press (KEY_HOME);
195
+ else if (key == " end" ) Keyboard.press (KEY_END);
196
+ else if (key == " pageup" ) Keyboard.press (KEY_PAGE_UP);
197
+ else if (key == " pagedown" ) Keyboard.press (KEY_PAGE_DOWN);
198
+ else if (key == " up" ) Keyboard.press (KEY_UP_ARROW);
199
+ else if (key == " down" ) Keyboard.press (KEY_DOWN_ARROW);
200
+ else if (key == " left" ) Keyboard.press (KEY_LEFT_ARROW);
201
+ else if (key == " right" ) Keyboard.press (KEY_RIGHT_ARROW);
202
+ else if (key == " ctrl" ) Keyboard.press (KEY_LEFT_CTRL);
203
+ else if (key == " shift" ) Keyboard.press (KEY_LEFT_SHIFT);
204
+ else if (key == " alt" ) Keyboard.press (KEY_LEFT_ALT);
205
+ else if (key == " gui" ) Keyboard.press (KEY_LEFT_GUI);
206
+ else if (key == " capslock" ) Keyboard.press (KEY_CAPS_LOCK);
207
+ else if (key == " numlock" ) Keyboard.press (KEY_NUM_LOCK);
208
+ else if (key == " prtsc" ) Keyboard.press (KEY_PRINT_SCREEN);
209
+ else if (key == " scrolllock" ) Keyboard.press (KEY_SCROLL_LOCK);
210
+ else if (key == " pause" ) Keyboard.press (KEY_PAUSE);
211
+ else if (key.startsWith (" F" )) {
212
+ const int fKey = key.substring (1 ).toInt ();
213
+ if (fKey >= 1 && fKey <= 24 ) {
214
+ Keyboard.press (KEY_F1 + (fKey - 1 ));
215
+ }
216
+ } else if (key.length () == 1 ) {
217
+ Keyboard.press (key[0 ]);
218
+ }
219
+ }
0 commit comments