Skip to content

Instantly share code, notes, and snippets.

@tokyoff
Last active September 12, 2019 14:52
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 tokyoff/48acf192a0aaf36e806b3d50d62a094a to your computer and use it in GitHub Desktop.
Save tokyoff/48acf192a0aaf36e806b3d50d62a094a to your computer and use it in GitHub Desktop.
範囲指定スクリーンショット機能が呼び出せるワンボタンキーボード用ソースコード
//------------------------------------
// 範囲指定スクリーンショット キーボード
// https://www.one-button-key.com/
//------------------------------------
#define WIN // ※Macの場合はdefineをコメントアウトして下さい
#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)) {
#ifdef WIN // Windowsの場合(Win10以降が対応)
Keyboard.press(KEY_LEFT_GUI); // win
Keyboard.press(KEY_LEFT_SHIFT); // shift
Keyboard.press('s'); // s
#else // Macの場合
Keyboard.press(KEY_LEFT_SHIFT); // shift
Keyboard.press(KEY_LEFT_GUI); // command
Keyboard.press('4'); // 4
#endif
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