Advertisement
Guest User

Holtek Gaming Mouse control script (NON-WORKING)

a guest
Sep 23rd, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. import usb.core
  2. import usb.util
  3.  
  4. print("Hello!")
  5. dev = usb.core.find(idVendor=0x04d9,idProduct=0xa070) #Found this using lsusb and also from the USBlyzer.
  6. #Can be found by name "Holtek gaming mouse" or "Anker 2000 DPI Game Mouse" other names also exist.
  7.  
  8. interface = 1
  9.  
  10. if dev is None:
  11.     raise ValueError("Device is not connected")
  12.  
  13. if dev.is_kernel_driver_active(interface) is True:
  14.     try:
  15.         dev.detach_kernel_driver(interface)
  16.     except usb.core.USBError as e:
  17.         raise ValueError("Failed to detatch kernel driver: %s" % str(e))
  18.        
  19. dev.detach_kernel_driver(1) #Interface 0 seems to be what we use.
  20. usb.util.claim_interface(dev, interface)
  21. dev.set_interface_altsetting(interface=interface,alternate_setting=0)
  22.  
  23. #Hardcoded commands just for testing. (Length is always 8 bytes?)
  24. start = [0x07, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00] #This is always sent before sending settings to the mouse.
  25. end = [0x07, 0x13, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00] #This is always sent after the settings have been sent to the mouse.
  26. color1 = [0x07, 0x09, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00] #This sets the color to blue
  27. bnm1 = [0x07, 0x0C, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00] #This sets the brightness to high and pulse mode to fast.
  28.  
  29. #bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001 from USBlyzer
  30. dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=start,timeout=1000) #Fails at here
  31. dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=color1,timeout=1000)
  32. dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=bnm1,timeout=1000)
  33. dev.ctrl_transfer(bmRequestType=0x22, bRequest=0x09, wValue=0x0307, wIndex=0x0001, data_or_wLength=end,timeout=1000)
  34.  
  35. print("End")
  36.  
  37. usb.util.release_interface(dev, interface)
  38. dev.attach_kernel_driver(interface)
  39.  
  40. print("Released interface and attached kernel driver(?)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement