Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ワンボタンキーボードの基本形ソースコード
#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
You can’t perform that action at this time.