Created
March 4, 2023 03:34
-
-
Save suapapa/95785a415fa09bb808233f80712d3e22 to your computer and use it in GitHub Desktop.
arduino: esc key only keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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