簡體   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