Skip to content

Commit b031a9a

Browse files
Update DigiKeyboard.h
added modification from https://hackaday.io/project/9277-oh-cheat/log/30813-extended-digispark-keyboard-library for custom key down time
1 parent 111396f commit b031a9a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,44 @@ class DigiKeyboardDevice : public Print {
176176
// This stops endlessly repeating keystrokes:
177177
sendKeyPress(0,0);
178178
}
179+
void sendKeyStroke(byte keyStroke, byte modifiers, uint16_t key_down_time) {
180+
while (!usbInterruptIsReady()) {
181+
// Note: We wait until we can send keystroke
182+
// so we know the previous keystroke was
183+
// sent.
184+
usbPoll();
185+
_delay_ms(5);
186+
}
187+
188+
memset(reportBuffer, 0, sizeof(reportBuffer));
189+
190+
reportBuffer[0] = modifiers;
191+
reportBuffer[1] = keyStroke;
192+
193+
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
194+
195+
while (!usbInterruptIsReady()) {
196+
// Note: We wait until we can send keystroke
197+
// so we know the previous keystroke was
198+
// sent.
199+
usbPoll();
200+
_delay_ms(5);
201+
}
202+
203+
// Pressing time (in milliseconds) that the key remains pressed
204+
// until is released. If is zero don't release the key (it should be
205+
// done manually by sendKeysStroke(0). Therefore minimum time is 1ms
206+
// and the maximum is 65535ms.
207+
if (key_down_time) {
208+
while (key_down_time--) {
209+
usbPoll();
210+
_delay_ms(1);
211+
}
212+
// Now send 'no key' pressed
213+
memset(reportBuffer, 0, sizeof(reportBuffer));
214+
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
215+
}
216+
}
179217

180218
//sendKeyPress: sends a key press only - no release
181219
//to release the key, send again with keyPress=0

0 commit comments

Comments
 (0)