@@ -15,7 +15,6 @@ void setup() {
15
15
16
16
Serial.begin (9600 );
17
17
Serial.println (" Hello keyboard passthrough" );
18
- // Keyboard.begin();
19
18
20
19
// Set the reset pin low for 10 ms.
21
20
digitalWrite (resetPin, LOW);
@@ -117,6 +116,14 @@ void loop() {
117
116
delayMicroseconds (baudDelay / 2 );
118
117
119
118
char key = getChar ();
119
+ int theKey = (int )key;
120
+ Serial.print (" Raw char: " );
121
+ Serial.print (key);
122
+ Serial.print (" (decimal " ); Serial.print (theKey); Serial.print (" =0b" );
123
+ for (int i = 7 ; i >= 0 ; i--) {
124
+ Serial.write (bitRead (theKey, i));
125
+ }
126
+ Serial.println (" )" );
120
127
sendChar (key);
121
128
}
122
129
}
@@ -136,15 +143,7 @@ char getChar() {
136
143
delayMicroseconds (baudDelay);
137
144
}
138
145
139
- char keyChar = (char )theKey;
140
- Serial.print (keyChar);
141
- Serial.print (" (dec " ); Serial.print (theKey); Serial.print (" =0b" );
142
- for (int i = 7 ; i >= 0 ; i--) {
143
- Serial.write (bitRead (theKey, i));
144
- }
145
- Serial.println (" )" );
146
-
147
- return keyChar;
146
+ return (char ) theKey;
148
147
}
149
148
150
149
bool nextIsAlt = false ;
@@ -154,24 +153,30 @@ void sendChar(char key) {
154
153
// Figure out what to do with the key
155
154
// * printable characters just get returned.
156
155
// * control characters: ctrl + letter
157
- // * numpad needs to get translated
158
- // * HELP is ??? (192)
159
- // * F1 (193)-F12 (204) need to be translated
160
156
// * F13 is "send next char as "alt""
161
157
// * F14 is "numLock toggle"
158
+ // * Other characters are translated.
162
159
if (key >= ' ' && i <= ' ~' ) {
163
160
if (nextIsAlt) {
164
161
Serial.print (" Alt+" ); Serial.println (key);
162
+ // Keyboard.begin();
165
163
// Keyboard.press(KEY_ALT)
166
164
// Keyboard.press(key);
165
+ // delay(100);// I've seen this elsewhere. sometimes 20 ms
167
166
// Keyboard.releaseAll();
167
+ // Keyboard.end();
168
168
nextIsAlt = false ;
169
169
return ;
170
170
}
171
+
171
172
Serial.print (" Printable: " ); Serial.println (key);
173
+ // Keyboard.begin();
174
+ // Keyboard.write(key);
175
+ // Keyboard.end();
172
176
return ;
173
177
}
174
178
179
+ // TODO: think about alt+ctrl+char, and alt+ctrl+shift+char
175
180
char translated;
176
181
if (numLock) {
177
182
translated = numLockTable[key];
@@ -188,16 +193,24 @@ void sendChar(char key) {
188
193
Serial.print (" F14: Toggling numlock " ); Serial.println (numLock);
189
194
} else if (key < ' ' ) {
190
195
Serial.print (" ctrl-" ); Serial.println (key+64 );
196
+ // Keyboard.begin();
191
197
// Keyboard.press(KEY_LEFT_CTRL);
192
198
// Keyboard.press(key + 64)
199
+ // delay(100);// I've seen this elsewhere. sometimes 20 ms
193
200
// Keyboard.releaseAll();
201
+ // Keyboard.end();
194
202
}
195
203
} else if (translated >= ' ' && translated <= ' ~' ) {
196
- Serial.print (" Printable: " ); Serial.print (translated); Serial.print (" ; was: " ); Serial.print ((int ) key);
197
- // Keyboard.print(translated);
204
+ Serial.print (" Printable: " ); Serial.print (translated); Serial.print (" ; was decimal: " ); Serial.print ((int ) key);
205
+ // Keyboard.begin();
206
+ // Keyboard.write(translated);
207
+ // Keyboard.end();
198
208
} else {
199
- Serial.print (" Unprintable: " ); Serial.print ((int ) translated); Serial.print (" ; was: " ); Serial.print ((int ) key);
209
+ Serial.print (" Unprintable: " ); Serial.print ((int ) translated); Serial.print (" decimal; was decimal: " ); Serial.print ((int ) key);
210
+ // Keyboard.begin();
200
211
// Keyboard.press(key);
212
+ // delay(100);// I've seen this elsewhere. sometimes 20 ms
201
213
// Keyboard.releaseAll();
214
+ // Keyboard.end();
202
215
}
203
216
}
0 commit comments