マウスカーソルを高速で動かせるワンボタンキーボード用ソースコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------ | |
// マウスカーソルを高速で動かせるキーボード | |
// ※キーを押すたびにカーソル移動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