Skip to content

Instantly share code, notes, and snippets.

@tokyoff
Created September 15, 2019 02:11
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/421c17365b69976ba773b857aa705864 to your computer and use it in GitHub Desktop.
Save tokyoff/421c17365b69976ba773b857aa705864 to your computer and use it in GitHub Desktop.
マウスカーソルを高速で動かせるワンボタンキーボード用ソースコード
//------------------------------------------
// マウスカーソルを高速で動かせるキーボード
// ※キーを押すたびにカーソル移動ON/OFFが可能
// https://www.one-button-key.com/
//------------------------------------------
#include "Mouse.h"
#define PIN_KEYSW (9)
int prevKeyState;
int currKeyState;
bool mouseOn;
int mouseMoveCnt;
void setup() {
pinMode(PIN_KEYSW, INPUT_PULLUP);
prevKeyState = HIGH;
currKeyState = HIGH;
mouseOn = false;
mouseMoveCnt = 0;
Mouse.begin();
}
void loop() {
currKeyState = digitalRead(PIN_KEYSW);
// キースイッチが押された
if ((prevKeyState == HIGH) && (currKeyState == LOW)) {
mouseOn = !mouseOn;
}
// マウスカーソルを動かす
if (mouseOn) {
if (mouseMoveCnt == 0) {
Mouse.move(10, 0);
}
else if (mouseMoveCnt == 1) {
Mouse.move(0, 10);
}
else if (mouseMoveCnt == 2) {
Mouse.move(-10, 0);
}
else {
Mouse.move(0, -10);
}
mouseMoveCnt++;
if (mouseMoveCnt >= 4) mouseMoveCnt = 0;
}
prevKeyState = currKeyState;
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment