Created
April 11, 2016 14:57
-
-
Save nv1t/1321088f40110018f3742b649063f830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
import usb.core | |
import usb.util | |
class pyMouse(object): | |
def __init__(self,vendor,product): | |
self.device = usb.core.find(idVendor=vendor, idProduct=product) | |
if self.device is None: | |
raise Exception("Couldn't find device %sx%s" %(vendor,product)) | |
else: | |
if self.device.is_kernel_driver_active(0): | |
self.device.detach_kernel_driver(0) | |
usb.util.claim_interface(device,0) | |
self.device.reset() | |
self.device.set_configuration() | |
return self | |
def button(self,n,fn): | |
if type(fn) != 'function': | |
raise Exception("Callback is not a function") | |
if n < 0 and n > 2: | |
raise Exception("Button Number not a Number between 0 and 2") | |
self.buttons[n] = fn | |
return self | |
def run(self): | |
while(True): | |
try: | |
n = [int(i) for i in device.read(0x81,6)] | |
self.buttons[0](n[1]&1 != 0) | |
self.buttons[1](n[1]&2 != 0) | |
self.buttons[2](n[1]&4 != 0) | |
time.sleep(.5) | |
except KeyboardInterrupt: | |
return -1 | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment