Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Keyboard.h>
#include <Bounce2.h>
#define NUM_BUTTONS 8
const uint8_t BUTTON_PINS[NUM_BUTTONS] = {13, 5, 10, 9, 8, 6, 12, 4};
Bounce2::Button * buttons = new Bounce2::Button[NUM_BUTTONS];
extern void openUrl(String url);
// array of function pointers
void (*keyActions []) () = {
[] {
openUrl("https://kernelcon.org");
delay(1000);
// Command + l
//Keyboard.press(KEY_LEFT_GUI); Keyboard.print("l"); delay(120); Keyboard.releaseAll();
//Keyboard.print("javascript:alert(location.href)\n");
} ,
[] { openUrl("https://twitch.kernelcon.org"); } ,
[] { openUrl("https://discord.kernelcon.org"); } ,
[] { openUrl("http://github.com/kernelcon/hacker-hotkey"); } ,
[] { Keyboard.println("!vote 4"); } ,
[] { Keyboard.println("!vote 3"); } ,
[] { Keyboard.println("!vote 2"); } ,
[] { Keyboard.println("!vote 1"); } ,
};
void setup() {
for (int i = 0; i < NUM_BUTTONS; i++) {
buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP );
buttons[i].interval(25);
buttons[i].setPressedState(LOW);
}
Keyboard.begin();
}
void loop() {
for (int i = 0; i < NUM_BUTTONS; i++) {
buttons[i].update();
if ( buttons[i].pressed() ) {
keyActions [i] ();
}
}
}
void openUrl(String url){
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(0x20);
delay(120);
Keyboard.releaseAll();
delay(100);
Keyboard.print(url);
delay(500);
Keyboard.print("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment