Skip to content

Instantly share code, notes, and snippets.

@suapapa
Created March 4, 2023 03:34
Show Gist options
  • Save suapapa/95785a415fa09bb808233f80712d3e22 to your computer and use it in GitHub Desktop.
Save suapapa/95785a415fa09bb808233f80712d3e22 to your computer and use it in GitHub Desktop.
arduino: esc key only keyboard
#include <Keyboard.h>
#define PIN_ESC_INPUT 8
char lastPress = 0;
char escKey = KEY_ESC;
void setup() {
pinMode(PIN_ESC_INPUT, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
if (digitalRead(PIN_ESC_INPUT) == HIGH) {
if (lastPress == 1) {
lastPress = 0;
digitalWrite(LED_BUILTIN, LOW);
Keyboard.releaseAll();
}
} else {
if (lastPress == 0) {
lastPress = 1;
digitalWrite(LED_BUILTIN, HIGH);
Keyboard.press(escKey);
}
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment