Skip to content

Commit 2c40bcd

Browse files
author
Erik Tylek Kettenburg
committed
Merge pull request #18 from eelmasllari/master
added functionality to send keypresses, i.e. a press without release
2 parents af7c58d + 6844d32 commit 2c40bcd

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,30 @@ class DigiKeyboardDevice : public Print {
163163
}
164164
}
165165

166+
//sendKeyStroke: sends a key press AND release
166167
void sendKeyStroke(byte keyStroke) {
167168
sendKeyStroke(keyStroke, 0);
168169
}
169170

171+
//sendKeyStroke: sends a key press AND release with modifiers
170172
void sendKeyStroke(byte keyStroke, byte modifiers) {
173+
sendKeyPress(keyStroke, modifiers);
174+
// This stops endlessly repeating keystrokes:
175+
sendKeyPress(0,0);
176+
}
177+
178+
//sendKeyPress: sends a key press only - no release
179+
//to release the key, send again with keyPress=0
180+
void sendKeyPress(byte keyPress) {
181+
sendKeyPress(keyPress, 0);
182+
}
183+
184+
//sendKeyPress: sends a key press only, with modifiers - no release
185+
//to release the key, send again with keyPress=0
186+
void sendKeyPress(byte keyPress, byte modifiers) {
171187
while (!usbInterruptIsReady()) {
172-
// Note: We wait until we can send keystroke
173-
// so we know the previous keystroke was
188+
// Note: We wait until we can send keyPress
189+
// so we know the previous keyPress was
174190
// sent.
175191
usbPoll();
176192
_delay_ms(5);
@@ -179,20 +195,8 @@ class DigiKeyboardDevice : public Print {
179195
memset(reportBuffer, 0, sizeof(reportBuffer));
180196

181197
reportBuffer[0] = modifiers;
182-
reportBuffer[1] = keyStroke;
198+
reportBuffer[1] = keyPress;
183199

184-
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
185-
186-
while (!usbInterruptIsReady()) {
187-
// Note: We wait until we can send keystroke
188-
// so we know the previous keystroke was
189-
// sent.
190-
usbPoll();
191-
_delay_ms(5);
192-
}
193-
194-
// This stops endlessly repeating keystrokes:
195-
memset(reportBuffer, 0, sizeof(reportBuffer));
196200
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
197201
}
198202

0 commit comments

Comments
 (0)