operative Posted May 3, 2010 Share Posted May 3, 2010 Hello everyone. this is my first code for the ducky / teensy 2.0 board. Written with the Arduino / Teensyduino tool. The code sends a random keystroke every 1 to 15 seconds. Random Key might be from "a" to "z" Sorry for the "dirty" switch/case stuff, i'm working on a version with char arrays. this has no special purpose. it's only to annoy some workmates ^^ int ledPin = 11; long randNumber; long randNumber2; void setup() { Serial.begin(9600); randomSeed(analogRead(0)); pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); // set the LED on randNumber2 = random(1,28); switch (randNumber2) { case 1: Keyboard.print("a"); break; case 2: Keyboard.print("b"); break; case 3: Keyboard.print("c"); break; case 4: Keyboard.print("d"); break; case 5: Keyboard.print("e"); break; case 6: Keyboard.print("f"); break; case 7: Keyboard.print("g"); break; case 8: Keyboard.print("h"); break; case 9: Keyboard.print("i"); break; case 10: Keyboard.print("j"); break; case 11: Keyboard.print("k"); break; case 12: Keyboard.print("l"); break; case 13: Keyboard.print("m"); break; case 14: Keyboard.print("n"); break; case 15: Keyboard.print("o"); break; case 16: Keyboard.print("p"); break; case 17: Keyboard.print("q"); break; case 18: Keyboard.print("r"); break; case 19: Keyboard.print("s"); break; case 20: Keyboard.print("t"); break; case 21: Keyboard.print("u"); break; case 22: Keyboard.print("v"); break; case 23: Keyboard.print("w"); break; case 24: Keyboard.print("x"); break; case 25: Keyboard.print("y"); break; case 26: Keyboard.print("z"); break; default: Keyboard.print("alr"); } delay(500); digitalWrite(ledPin, LOW); randNumber = random(15000); delay(randNumber); } Quote Link to comment Share on other sites More sharing options...
NanoyMaster Posted May 3, 2010 Share Posted May 3, 2010 Something like this should work... I havn't tested it tho. I'm pretty sure you can work out how to get lowercase/numbers etc... hope this helps long randNumber; long randNumber2; void setup(){ randomSeed(analogRead(0)); pinMode(11, OUTPUT); } char* alphabet[] = { "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; void loop(){ digitalWrite(11, HIGH); // set the LED on randNumber2 = random(1,26); Keyboard.print(alphabet[randNumber2]); delay(500); digitalWrite(11, LOW); randNumber = random(15000); delay(randNumber); } Quote Link to comment Share on other sites More sharing options...
Netshroud Posted May 3, 2010 Share Posted May 3, 2010 Take a look at what I've done to convert ASCII to keycodes in PsyDuk. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.