Jump to content

hid usb mouse. like rubber ducky automation. hex code confusion


g0tmilk

Recommended Posts

im building a mouse and keyboard usb from a rasperry pi. i have a working example with the mouse. but im confused about the x and y location

documentation shows that both x and y consist of 2 values. a negative and positive 

x= -127 and 127

y= -127 and 127

so is there math involved? what is it?

i can get the mouse to move by writing to the /dev/hidg0

echo -ne "\x00\x00\x40\x00\x40\x00\x00\x00" > /dev/hidg0

hex40=64

this command will locate the mouse to the center of my screen. but i cant get it to move one pixel at a time.

im using ruby to automate this but i dont understand the coordinate system. since x and y require the use of a negative and a positive.

Link to comment
Share on other sites

On 7/7/2022 at 7:34 AM, dark_pyrro said:

What documentation are you using when developing this? Any official/public reference?

 

Here is a article that will get a working example.

https://forums.raspberrypi.com/viewtopic.php?t=234495

 

 

#!/bin/bash
# mouse
cd /sys/kernel/config/usb_gadget/
mkdir -p isticktoit
cd isticktoit
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 "Tobias Girstmair" > strings/0x409/manufacturer
echo "iSticktoit.net USB Device" > 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 3 > functions/hid.usb0/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.usb0/report_desc
ln -s functions/hid.usb0 configs/c.1/

ls /sys/class/udc > UDC

 

Chmod +x this bash script to enable the otg on the pi and your windows pc will see the pi as a new mouse.

Then a quick test will move your mouse.

On the pi run

Echo -ne "\x00\x09\x09" > /dev/hidg0

Moves the mouse 9 pixles up and right.

 

But with this config i found that if you run the command multiple times its inacurate. And wont work for me.

 

Ill explain more on my lunch break

Link to comment
Share on other sites

I can't see where in the referenced "documentation" that the previously mentioned positive (127) and negative (-127, or -128) fit in. That type of "range" is used in other specifications for mouse control though. It should be used as a positioning reference based on the current position of the pointer, not aligned to any form of fixed grid. Arduino HID class/libraries use that form when "addressing" the position. Negative numbers moving the cursor down/left, positive numbers move the cursor right/up.

Link to comment
Share on other sites

3 hours ago, dark_pyrro said:

I can't see where in the referenced "documentation" that the previously mentioned positive (127) and negative (-127, or -128) fit in. That type of "range" is used in other specifications for mouse control though. It should be used as a positioning reference based on the current position of the pointer, not aligned to any form of fixed grid. Arduino HID class/libraries use that form when "addressing" the position. Negative numbers moving the cursor down/left, positive numbers move the cursor right/up.

Here is the git i used for the first post. 

https://github.com/jonatanklosko/gerbil

 

And below is the configure source file with bit codes to enable hidg0 that has me confused on the 8 bytes that include (-x , +x, -y, +y)

https://github.com/jonatanklosko/gerbil/blob/main/bin/enable_mouse_hid_gadget.sh

 

This is the config report

\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\x00\x26\xff\x7f\x75\x10\x95\x02\x81\x02\xc0\xc0

 

# Write the report descriptor
  #
  # 0x05, 0x01, // Usage Page (Generic Desktop)
  # 0x09, 0x02, // Usage (Mouse)
  # 0xa1, 0x01, // Collection (Application)
  # 0x09, 0x01, // Usage (Pointer)
  # 0xa1, 0x00, // Collection (Physical)
  # 0x05, 0x09, // Usage Page (Buttons)
  # 0x19, 0x01, // Usage Minimum (Button 1)
  # 0x29, 0x03, // Usage Maximum (Button 3)
  # 0x15, 0x00, // Logical Minimum (0)
  # 0x25, 0x01, // Logical Maximum (1)
  # 0x95, 0x03, // Report Count (3)
  # 0x75, 0x01, // Report Size (1)
  # 0x81, 0x02, // Input (Data, Variable, Absolute)
  # 0x95, 0x01, // Report Count (1)
  # 0x75, 0x05, // Report Size (5)
  # 0x81, 0x03, // Input (Constant, Variable, Absolute)
  # 0x05, 0x01, // Usage Page (Generic Desktop)
  # 0x09, 0x30, // Usage (X)
  # 0x09, 0x31, // Usage (Y)
  # 0x15, 0x00, // Logical Minimum (0)
  # 0x26, 0xff, 0x7f, // Logical Maximum (32767)
  # 0x75, 0x10, // Report Size (16)
  # 0x95, 0x02, // Report Count (2)
  # 0x81, 0x02, // Input (Data, Variable, Absolute)
  # 0xc0, // End Collection
  # 0xc0 // End Collection
  #
 
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...