鼠标与键盘 USB-HID 函式库
86Duino IDE 从 Coding 104 开始加入此函式库,当您将 86Duino 板子插上电脑后,会出现 86Duino 的 HID USB 键盘和鼠标装置。
使用鼠标与键盘 USB-HID 函式库时,需要注意: 当鼠标和键盘正不断在运作时,它将干扰您编辑或烧录 sketch 的过程,像是 Mouse.move()
和 Keyboard.print()
函式,它会不断移动您的鼠标以及按下您的键盘按键。建议您在 sketch 程式中,替这些函式加上一些启动条件,使鼠标或键盘的行为变成可控,例如:按下某个开关或者读到某个 pin 为指定的输入后,才呼叫函式。
当您在使用 Mouse
或者 Keyboard
函式库时,建议您搭配使用 Serial.print()
函式来输出讯息,如此一来,您就可以知道 86Duino 送给电脑的实际数值。
鼠标
当 86Duino 与电脑连接时,它可以控制电脑上的鼠标行为。注意:当鼠标的位置被更新时(移动鼠标),总是会回传距离上次位置的相对值。
- Mouse.begin()
- Mouse.click()
- Mouse.end()
- Mouse.move()
- Mouse.press()
- Mouse.release()
- Mouse.isPressed()
键盘
当 86Duino 与电脑连接时,它可以控制电脑上的键盘行为。注意:这个函式库并不能回传每一个 ASCII 字元(尤其是那些不可印出的字元)。另外,这个函式库支援修饰键(modifier key),这是键盘上的特殊键,例如:shift 键和 ctrl 键。当同时按下 shift 键和 n 键,你会得到大写的 N 字元;或者在打开 86Duino IDE 视窗中,按下 ctrl 键和 n 键,即开启一个新的 sketch 页面。请点 这里 了解更多修饰键(modifier key)的说明。
- Keyboard.begin()
- Keyboard.end()
- Keyboard.press()
- Keyboard.print()
- Keyboard.println()
- Keyboard.release()
- Keyboard.releaseAll()
- Keyboard.write()
范例
以下是鼠标
和键盘
的使用范例,这些范例都是来自 Arduino 使用手册,它们也能在 86Duino 板子上运行:
- KeyboardAndMouseControl:在一个 sketch 中,示范鼠标和键盘的命令。
- KeyboardMessage:当按下一个外部按钮时,用键盘自动打出一段文字。
- KeyboardLogout:使用键盘命令来登出电脑。
- KeyboardSerial:从序列埠读取字元,然后按下键盘上相同的字元。
- ButtonMouseControl:使用 5 个外部按钮来移动鼠标。
- JoystickMouseControl:当按下摇杆按钮时,可以用摇杆来移动鼠标。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.