概要
arduino leonardoでusbキーボード、usbマウスをエミュレートしてみた。
写真
写真
サンプルコード
void setup()
{
pinMode(8, INPUT_PULLUP);
Serial.begin(115200);
while (!Serial);
Keyboard.begin();
Mouse.begin();
Serial.println("Start");
}
void loop()
{
int x, y;
if (digitalRead(8) == HIGH)
{
//Serial.println("off");
}
else
{
Serial.println("on");
Keyboard.press(KEY_LEFT_GUI);
delay(100);
Keyboard.press('r');
delay(500);
Keyboard.releaseAll();
delay(500);
Keyboard.print("mspaint");
Keyboard.press(KEY_TAB);
Keyboard.press(KEY_RETURN);
delay(500);
Keyboard.releaseAll();
delay(700);
Mouse.press();
for (float r = 0; r <= 3.1415 * 2; r += 0.01)
{
x = sin(5.0 * r) * 5.0;
y = cos(8.0 * r) * 5.0;
Mouse.move(x, y, 0);
delay(10);
}
Mouse.release();
}
delay(100);
}