I checked the contents of the library..
Joystick.pressButton(x);
And
Joystick.releaseButton(x);
This is sent key to the PC instantly.
by you setting below.
const bool initAutoSendState = true;
In other words
Joystick.pressButton(x);
Joystick.releaseButton(x);
This is will be button is pressed once.
For the time being, forget once about the toggle switch...
{
static bool isNotPressed = true;
if (digitalRead(8) == LOW)
{
if (isNotPressed)
{
Joystick.pressButton(4);
Joystick.releaseButton(4);
Joystick.pressButton(4);
Joystick.releaseButton(4);
isNotPressed = false;
}
} else {
isNotPressed = true;
}
}
Please possible to check if the key sent twice with the this code?
Try replacing the "8-button" in your code with this one.
There was an extra curly brace, but I dare to leave it as it is.