HID 模拟键鼠

MXCube 生成的时候会缺少很多环境,需要手动添加
修改 c_cpp_properties.json 如下:

...
        "user_cSources": [
            "Src/usb_device.c",
            "Src/usbd_conf.c",
            "Src/usbd_desc.c",
            "Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c",
            "Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c",
            "Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c",
            "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c",
            "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c",
            "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c",
            "Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c"
        ],
        "user_asmSources": [],
        "user_cIncludes": [
            "Middlewares/ST/STM32_USB_Device_Library/Core/Inc",
            "Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc",
            "Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc"
        ],
        "user_asmIncludes": [],
...

Modifiers

Bit Key
0 LEFT CTRL
1 LEFT SHIFT
2 LEFT ALT
3 LEFT GUI
4 RIGHT CTRL
5 RIGHT SHIFT
6 RIGHT ALT
7 RIGHT GUI

Keys
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
53 页


  HAL_Delay(2000);
  click_report[0] = 0b0010; // GUI rchromechromechrome
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x15; // R
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x00; // GUI key
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(500);

  click_report[0] = 0x00; // GUI key  
  click_report[2] = 0x06;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x0B;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x15;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x12;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x10;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x08;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);
  USBD_Delay(delay_time);
  click_report[2] = 0x00;
  USBD_HID_SendReport(&hUsbDeviceFS, click_report, CLICK_REPORT_SIZE);

参考文章
https://damogranlabs.com/2018/02/stm32-usb-hid-mouse-keyboard/

你可能感兴趣的:(HID 模拟键鼠)