繁体   English   中英

Raspberry Pi 4 上的鼠标仿真不起作用

[英]Mouse emulation on Raspberry Pi 4 does not work


对于一个个人项目,我目前正在尝试让我的 Raspberry Pi 4 模拟键盘和鼠标。 键盘仿真效果非常好并且令人信服,但是在仿真鼠标时我一直遇到问题。
我已将我的 Pi 配置为 HID 设备,并在启动时执行以下代码:
 #!\/bin\/bash cd \/sys\/kernel\/config\/usb_gadget\/ mkdir -p pihid cd pihid echo 0x1d6b > idVendor # Linux Foundation echo 0x0104 > idProduct # Multifunction Composite Gadget echo 0x0100 > bcdDevice # v1.0.0 echo 0x0200 > bcdUSB # USB2 mkdir -p strings\/0x409 echo "fedcba9876543210" > strings\/0x409\/serialnumber echo "test" > strings\/0x409\/manufacturer echo "PiHID" > strings\/0x409\/product mkdir -p configs\/c.1\/strings\/0x409 echo "Config 1: ECM network" > configs\/c.1\/strings\/0x409\/configuration echo 250 > configs\/c.1\/MaxPower # Add functions here mkdir -p functions\/hid.usb0 echo 1 > functions\/hid.usb0\/protocol echo 1 > functions\/hid.usb0\/subclass echo 8 > functions\/hid.usb0\/report_length echo -ne \\\\x05\\\\x01\\\\x09\\\\x06\\\\xa1\\\\x01\\\\x05\\\\x07\\\\x19\\\\xe0\\\\x29\\\\xe7\\\\x15\\\\x00\\\\x25\\\\x01\\\\x75\\\\x01\\\\x95\\\\x08\\\\x81\\\\x02\\\\x95\\\\x01\\\\x75\\\\x08\\\\x81\\\\x03\\\\x95\\\\x05\\\\x75\\\\x01\\\\x05\\\\x08\\\\x19\\\\x01\\\\x29\\\\x05\\\\x91\\\\x02\\\\x95\\\\x01\\\\x75\\\\x03\\\\x91\\\\x03\\\\x95\\\\x06\\\\x75\\\\x08\\\\x15\\\\x00\\\\x25\\\\x65\\\\x05\\\\x07\\\\x19\\\\x00\\\\x29\\\\x65\\\\x81\\\\x00\\\\xc0 > functions\/hid.usb0\/report_desc ln -s functions\/hid.usb0 configs\/c.1\/ mkdir -p functions\/hid.usb1 echo 2 > functions\/hid.usb1\/protocol echo 2 > functions\/hid.usb1\/subclass echo 8 > functions\/hid.usb1\/report_length echo -ne \\\\x05\\\\x01\\\\x09\\\\x02\\\\xA1\\\\x01\\\\x09\\\\x01\\\\xA1\\\\x00\\\\x05\\\\x09\\\\x19\\\\x01\\\\x29\\\\x03\\\\x15\\\\x00\\\\x25\\\\x01\\\\x95\\\\x03\\\\x75\\\\x01\\\\x81\\\\x02\\\\x95\\\\x01\\\\x75\\\\x05\\\\x81\\\\x03\\\\x05\\\\x01\\\\x09\\\\x30\\\\x09\\\\x31\\\\x15\\\\x81\\\\x25\\\\x7F\\\\x75\\\\x08\\\\x95\\\\x02\\\\x81\\\\x06\\\\xC0\\\\xC0 > functions\/hid.usb1\/report_desc ln -s functions\/hid.usb1 configs\/c.1\/ # End functions ls \/sys\/class\/udc > UDC<\/code><\/pre>

启动后\/dev<\/code>中有两个文件,名为“hidg0”和“hidg1”,我应该能够写入。 使用此 python 脚本将键盘命令写入“hidg0”完全可以正常工作:

当我在编辑器中时,会出现“cdefgh”。

这是我用来写入“hidg1”的脚本:

但是在执行之后,不是将鼠标移动 100 个单位,而是什么也没有发生,程序结束了。 关于鼠标仿真或与 Windows HID 驱动程序的通信,我做错了什么?

"

大家都想清楚了吗? 不是,我认为鼠标需要 3 个字节而不是 8 个字节。另外,尝试使用 wb+ 而不是 rb+

NULL_CHAR = 字符(0)

def ms_write(report): with open("\/dev\/hidg1", "wb+") as fd: fd.write(report.encode())

ms_write(NULL_CHAR+chr(100)+NULL_CHAR)

ms_write(NULL_CHAR*3)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM