用Arduino Leonardo制作虚拟键盘(简易badusb)

Leonardo是Arduino开发板的一种型号,可以像其他Arduino板一样对Leonardo进行编程和使用。但是,有一些重要的区别:

The Leonardo differ from other Arduino boards in that they use a single microcontroller to both run your sketches and for USB communication with the computer. The Uno and other boards use separate microcontrollers for these two functions, meaning that the USB connection to the computer remains established regardless of the state of the main microcontroller. By combining these two functions onto a single processor, the Leonardo allows for more flexibility in its communication with the computer. It also helps to lower the cost of the board by removing the need for an additional processor.

Arduino Leonardo不同于之前全部的Arduino控制器,他直接使用了ATmega32u4的USB通信功能,取消了USB转UART芯片。这使得Leonardo不仅可以作为一个虚拟的COM端口,还可以作为鼠标或者键盘连接到计算机。

今天用Arduino Leonardo做的东西很花里胡哨,先来看看效果吧:

虚拟键盘演示(badusb)


以下是视频链接:
http://v.youku.com/v_show/id_XNDQ3ODExMDIwOA==.html?x&sharefrom=android&sharekey=4c06da3938ffd6ead4184f1d59feef9f6

先在Arduino IDE里新建一个文件,导入资源库:

#include <Keyboard.h>

这是键盘操作的库,只能在Arduino Leonardo系列的开发板上使用,如果在Arduino UNO 上编译的话,会报错

接下来我们需要学习一些虚拟键盘的语句:

开始键盘通讯:

Keyboard.begin();//开始键盘通讯 

按键操作:

Keyboard.press();

与按键对应的是释放:

Keyboard.release();

当然还可以输入:

Keyboard.println("");

最后是结束键盘通讯:

Keyboard.end();//结束键盘通讯 

有了这些基础,就可以大胆地发挥想象啦!

比如说,我想要的效果是:把开发板插入电脑后,打开命令行,给命令行变颜色

for(int i=0;i<10;i++)
  
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.郑先生_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值