即使我包括 Keyboard.h 也找不到键盘

Keyboard not found even though I'm including Keyboard.h

我想制作一个简单的程序放在我的 Arduino/Genuino (Sunfounder) Uno 板上,当插入时,它会调用 Keyboard.print() 函数。当我编译我的程序来执行此操作时,它说我没有包括 Keyboard.h,即使我实际上在程序的开头。

我的代码:

#include <Keyboard.h>

void setup() {
  Keyboard.begin();
  Keyboard.print("Hello, world!");
  Keyboard.end();
}


void loop() {

}

当我编译代码时,我得到这个错误:

KeyboardMessage:4:3: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

我在 Arduino 草图编辑器文件中检查了我的库文件,Keyboard.h 在那里。

感谢任何帮助。

Arduino/Genuino Uno 不支持键盘。您可以在 hardware/ardunino/avr/libraries/HID/HID.h 中看到它。此文件来自 Keyboard.h,包含 #if defined(USBCON)。但是 USBCON 没有为 Arduino/Genuino Uno 定义。 Keyboard.h

您需要使用另一个板

以下控制器支持它:

  • ATmega32U6
  • ATmega8U2
  • ATmega16U2
  • ATmega16U4
  • ATmega32U2
  • ATmega32U4
  • 和一些 ATxxUSBxx

Arduino/Genuino Uno 使用 ATmega32U8。

你知道你现在不需要 32u4 什么了,我通过 any Arduino 找到了使用键盘和鼠标的解决方案。

你所要做的就是这样:

Serial.println("pressA")

在 Arduino 上

前往 python 脚本并执行此操作:

import serial
import pyautogui
Arduino_Serial = serial.Serial('COM5', 9600)

while 1:
    incoming_data = str(Arduino_Serial.readline())
    print(incoming_data)
    if 'pressA' in incoming_data:
        pyautogui.press('a')
    incoming_data = ""