Skip to content

Instantly share code, notes, and snippets.

@tokyoff
Last active December 3, 2021 22:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tokyoff/02f89096e0a5ea5663a02d36e0ad9fff to your computer and use it in GitHub Desktop.
Save tokyoff/02f89096e0a5ea5663a02d36e0ad9fff to your computer and use it in GitHub Desktop.
ワンボタンキーボードの基本形ソースコード
#include "Keyboard.h"
#define PIN_KEYSW (9)
int prevKeyState;
int currKeyState;
void setup() {
pinMode(PIN_KEYSW, INPUT_PULLUP);
prevKeyState = HIGH;
currKeyState = HIGH;
Keyboard.begin();
}
void loop() {
currKeyState = digitalRead(PIN_KEYSW);
// キースイッチが押された
if ((prevKeyState == HIGH) && (currKeyState == LOW)) {
// ↓↓↓ ここに好きなキー入力を書く ↓↓↓
// 例:[Ctrl]+[v]
Keyboard.press(KEY_LEFT_CTRL); // [Crtl]を押す
Keyboard.press('v'); // [v]を押す
delay(10); // 10ms待つ
Keyboard.releaseAll(); // すべて放す
// ↑↑↑ ここまで ↑↑↑
}
prevKeyState = currKeyState;
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment