那天自己买到了一个 arduinoLeonardo板子听说能做badusb然后去网上查了资料就顺手备份一下_(:з」∠)_了
keyboard库,功能就是将arduino Leonardo模拟成一个usb键盘,Api如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| 【输入宏定位】
|
具体代码语法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Keyboard.begin(); //开始
Keyboard.end(); //结束
Keyboard.press(); //按下
Keyboard.print("#"); ////模拟键盘敲出一个字符
Keyboard.println("#"); //模拟键盘敲出一个字符并添加换行的过程
Keyboard.release(); //松开
Keyboard.releaseAll(); //释放所有按键
Keyboard.write(); //仅支持键盘上的ASCII字符。
PS:Keyboard. press()和Keyboard.release()//请成对使用,防止出现按键被按下没有松开的情况
|
演示代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<Keyboard.h>
void setup();
Keyboard.begin();
delay(1000);
Keyboard.press(KEY_CAPS_LOCK);
Keyboard.release(KEY_CAPS_LOCK);
delay(500);
Keyboard.press(KEY_LEFT_GUI);
delay(500);
Keyboard.press('r');
delay(500);
Keyboard.release(KEY_LEFT_GUI);
Keyboard.release('r');
delay(500);
Keyboard.println("cmd");
delay(500);
Keyboard.press(KEY_RETURN);
Keyboard.release(KEY_RETURN);
delay(500);
Keyboard.println("hello world");
Keyboard.press(KEY_RETURN);
Keyboard.release(KEY_RETURN);
delay(500);
Keyboard.press(KEY_CAPS_LOCK);
Keyboard.release(KEY_CAPS_LOCK);
delay(500);
Keyboard.end();
|