Step 4Teensy Code
/*
Reddit Upvote/Downvote Button
This code sends the keystroke "CTRL + SHIFT + A" or "CTRL + SHIFT + Z" to your PC
or Mac. Make sure you set your Arduino compatible board to "Keyboard + Mouse" in
the "USB Type" menu. Hotkeys can be changed easily, I've added comments to make it
easier to find.
For this to work with Reddit as an Upvote/Downvote button you will need to install
Reddit Enhancement Suite (http://reddit.honestbleeps.com/) and set your Upvote and
Downvote hotkeys to the ones assigned in this Arduino sketch.
Code examples edited and reworked from http://wwww.arduino.cc and
http://www.pjrc.com/teensy
TheNewHobbyist 2011 <http://www.thenewhobbyist.com>
*/
// The inputs you're using for button presses
const int upVote = 8; // Upvote
const int downVote = 5; // Downvote
int upVoteStatus = 0;
int downVoteStatus = 0;
void setup() {
pinMode(upVote, INPUT);
pinMode(downVote, INPUT);
}
void loop(){
// Check the buttons
upVoteStatus = digitalRead(upVote);
downVoteStatus = digitalRead(downVote);
// If Upvote button is pressed
if (upVoteStatus == HIGH) {
// Change the following two lines to change the keys sent
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_SHIFT);
Keyboard.set_key1(KEY_A);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(500);
}
// If Downvote button is pressed
if (downVoteStatus == HIGH) {
// Change the following two lines to change the keys sent
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_SHIFT);
Keyboard.set_key1(KEY_Z);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(500);
}
}
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|









































