Hi,
I am not sure if I understood the problem, but if you want to send only ONE "a" when the button is pressed and stays pressed, and want the next "a" sent only after the button is released and pressed again, you only need a variable which remembers the button state.
But you have to append a DigiKeyboard.sendKeyStroke(0) after the DigiKeyboard.sendKeyStroke(4), otherwise the PC keyboard driver will handle the keystroke(4) with autorepeat, producing a row of "a's" by itself (proof: the row of "a's" even does not stop if you remove the DigiSpark).
#include <DigiKeyboard.h>
char PIN_BUTTON = 0;
char ButtonPressed = 0;
void setup()
{
// button pin as inputs
pinMode(PIN_BUTTON, INPUT);
// activate internal pull-up resistor
digitalWrite(PIN_BUTTON, HIGH);
}
void loop()
{
DigiKeyboard.sendKeyStroke(0);
if (digitalRead(PIN_BUTTON) == LOW)
{
if (ButtonPressed ==0)
{
// send "a"
DigiKeyboard.sendKeyStroke(4);
// send "Stop last Keystroke", otherwise the PC keyboard driver
// produces a row of "a's"
DigiKeyboard.sendKeyStroke(0);
// only one "a" until Button is released
ButtonPressed = 1;
}
}
if (digitalRead(PIN_BUTTON) == HIGH)
// Button released
{
ButtonPressed = 0;
}
}
Thanks for the reply. This seems to be easier than I thought it would be. Maybe I just didn't know what sendKeyStroke(0) is, after all

I will give it a go whenever I get home later today!
Edit: Now that I am taking a look at it again, I think this is going to send
one 'a', then send nothing while the button is pressed, is that correct? If so that's not the behavior I am expecting.
I need something like Keyboard.press('A') while the button is pushed and then Keyboard.release() when it goes HIGH (as seen in Leonardo-compatible boards).
Which, in other words, would be a persistent signal instead of a single input and the idle