16th
June
2017
How to use Teensyduino to send cmd + enter
Recently we purchased a bunch of Teensyduino powered buttons for a trivia game we were building for a client’s convention as a fun learning experience. Now that the conference is through, the buttons are sitting unused, and my boss asked me if I could reprogram one of them so he could use it to send emails through Outlook on Mac.
It was a fun little exercise since I’ve never worked with programming Teensyduinos before. It turned out that this wasn’t so complicated to accomplish. I figured I’d share the script in case anyone else would find it useful.
int key1 = KEY_ENTER; int spacesAllowed = 1; void setup() { Serial.begin(9600); pinMode(10, INPUT); digitalWrite(10, HIGH); // C7 } void loop() { if (digitalRead(10) == LOW && spacesAllowed > 0){ Keyboard.set_modifier(MODIFIERKEY_GUI); Keyboard.set_key1(key1); Keyboard.send_now(); delay(5); spacesAllowed = 0; // no spaces allowed anymore } if (digitalRead(10) == HIGH){ Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now(); delay(5); spacesAllowed = 1; // button is up again } }
If you need to send through Outlook on Windows, change the line
Keyboard.set_modifier(MODIFIERKEY_GUI);
to
Keyboard.set_modifier(MODIFIERKEY_CTRL);