Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
マウスカーソルを高速で動かせるワンボタンキーボード用ソースコード
//------------------------------------------
// マウスカーソルを高速で動かせるキーボード
// ※キーを押すたびにカーソル移動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