public
Created

  • Download Gist
USB_HID_Random.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/* Arduino USB HID Keyboard Demo
* Random Key/Random Delay
*/
 
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
 
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}
 
void loop()
{
int randomChar = random(4, 130);
long randomDelay = random(1000, 10000);
 
delay(randomDelay);
 
buf[2] = randomChar; // Random character
Serial.write(buf, 8); // Send keypress
releaseKey();
}
 
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.