I am trying to get the mouse raw data with pywinusb.
import pywinusb.hid as hid
def sample_handler(data):
print("Received raw data")
print(f"Data Type: {type(data)}, Data Length: {len(data)}")
print("Raw data: {0}".format(data))
def find_mouse_device():
all_hids = hid.HidDeviceFilter().get_devices()
for device in all_hids:
print(f"Device found: {device.product_name} (Vendor ID: {device.vendor_id}, Product ID: {device.product_id})")
if 'mouse' in device.product_name.lower():
return device
return None
def main():
mouse = find_mouse_device()
if mouse:
print(f"Mouse found: {mouse.product_name} (Vendor ID: {mouse.vendor_id}, Product ID: {mouse.product_id})")
try:
mouse.open()
print("Device opened successfully.")
mouse.set_raw_data_handler(sample_handler)
print("Raw data handler set.")
print("Listening for raw data... (Press Ctrl+C to stop)")
try:
while True:
pass
except KeyboardInterrupt:
print("Stopping...")
finally:
mouse.close()
print("Device closed.")
except Exception as e:
print(f"Error: {e}")
else:
print("No mouse found.")
if __name__ == "__main__":
main()
This outputs this Device found: Gaming Mouse G402 (Vendor ID: 1133, Product ID: 49278) Mouse found: Gaming Mouse G402 (Vendor ID: 1133, Product ID: 49278) Device opened successfully. Raw data handler set. Listening for raw data... (Press Ctrl+C to stop) Stopping... Device closed.
Which finds the rigth mouse, but it isnt capturing any data. I was also trying libusb and pyusb but I got the backend unavailable error.