Skip to content

Instantly share code, notes, and snippets.

@lucascolusso
Created July 20, 2019 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascolusso/732f521e0ddc6bc86755527f287d8f04 to your computer and use it in GitHub Desktop.
Save lucascolusso/732f521e0ddc6bc86755527f287d8f04 to your computer and use it in GitHub Desktop.
A shortcut keyboard for designers
#define KEY_LEFT_CTRL 0x01
#define KEY_LEFT_SHIFT 0x02
#define KEY_LEFT_ALT 0x04uint8_t buf[8] = {
0 }; /* Keyboard report buffer */#define PIN_COPY 7
#define PIN_CUT 5
#define PIN_PASTE 6
#define PIN_EYEDROP 4
#define PIN_LOCK 3
#define PIN_SAVE 2int state = 1;void setup()
{
Serial.begin(9600);pinMode(PIN_COPY, INPUT);
pinMode(PIN_CUT, INPUT);
pinMode(PIN_PASTE, INPUT);
pinMode(PIN_EYEDROP, INPUT);
pinMode(PIN_LOCK, INPUT);
pinMode(PIN_SAVE, INPUT); // Enable internal pull-ups
digitalWrite(PIN_COPY, 1);
digitalWrite(PIN_CUT, 1);
digitalWrite(PIN_PASTE, 1);
digitalWrite(PIN_EYEDROP, 1);
digitalWrite(PIN_SAVE, 1);
digitalWrite(PIN_LOCK, 1);delay(200);
}void loop()
{
state = digitalRead(PIN_CUT);
if (state != 1) {
buf[0] = KEY_LEFT_CTRL; // Ctrl
buf[2] = 27; // Letter X
// buf[2] = 123; // Cut key: Less portable
Serial.write(buf, 8); // Ssend keypress
releaseKey();
}state = digitalRead(PIN_COPY);
if (state != 1) {
buf[0] = KEY_LEFT_CTRL; // Ctrl
buf[2] = 6; // Letter C
// buf[2] = 124; // Copy key: Less portable
Serial.write(buf, 8); // Send keypress
releaseKey();
}state = digitalRead(PIN_PASTE);
if (state != 1) {
buf[0] = KEY_LEFT_CTRL; // Ctrl
buf[2] = 25; // Letter V
// buf[2] = 125; // Paste key: Less portable
Serial.write(buf, 8); // Send keypress
releaseKey();
}state = digitalRead(PIN_EYEDROP);
if (state != 1) {
buf[0] = 0; // Empty Buffer[0]
buf[2] = 0x0C; // Letter I
Serial.write(buf, 8); // Send keypress
releaseKey();
}state = digitalRead(PIN_SAVE);
if (state != 1) {
buf[0] = KEY_LEFT_CTRL + KEY_LEFT_SHIFT + KEY_LEFT_ALT;
buf[2] = 0x16; //S Key
Serial.write(buf, 8); // Send keypress
releaseKey();
}state = digitalRead(PIN_LOCK);
if (state != 1) {
buf[0] = KEY_LEFT_CTRL;
buf[2] = 0x1F; // 2 Key
Serial.write(buf, 8); // Send keypress
releaseKey();
}
}void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment