使用官方的pywinusb-master中的raw_data.py这个demo 无法读取到鼠标hib设备的数据,能够读到pid,vid
device.set_raw_data_handler(sample_handler)执行完以后,就一直收不到数据。
#!/usr/bin/env python # -*- coding: utf-8 -*- # """ Handling raw data inputs example """ from time import sleep from msvcrt import kbhit import pywinusb.hid as hid def sample_handler(data): print("Raw data: {0}".format(data)) def raw_test(): # simple test # browse devices... all_hids = hid.find_all_hid_devices() if all_hids: while True: print("Choose a device to monitor raw input reports:\n") print("0 => Exit") for index, device in enumerate(all_hids): device_name = unicode("{0.vendor_name} {0.product_name}" \ "(vID=0x{1:04x}, pID=0x{2:04x})"\ "".format(device, device.vendor_id, device.product_id)) print("{0} => {1}".format(index+1, device_name)) print("\n\tDevice ('0' to '%d', '0' to exit?) " \ "[press enter after number]:" % len(all_hids)) index_option = raw_input() if index_option.isdigit() and int(index_option) <= len(all_hids): # invalid break; int_option = int(index_option) if int_option: device = all_hids[int_option-1] try: device.open() #set custom raw data handler device.set_raw_data_handler(sample_handler) print("\nWaiting for data...\nPress any (system keyboard) key to stop...") while not kbhit() and device.is_plugged(): #just keep the device opened to receive events sleep(0.5) return finally: device.close() else: print("There's not any non system HID class device available") # if __name__ == '__main__': # first be kind with local encodings import sys if sys.version_info >= (3,): # as is, don't handle unicodes unicode = str raw_input = input else: # allow to show encoded strings import codecs sys.stdout = codecs.getwriter('mbcs')(sys.stdout) raw_test()
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。