import pywinusb.hid as hid
from time import sleep
from msvcrt import kbhit
def take_data():
all_hids = hid.find_all_hid_devices()
int_option = 6
device = all_hids[int_option-1]
try:
device.open()
#set custom raw data handler
device.set_raw_data_handler(print)
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
except Exception as e:
print("error")
finally:
device.close()
take_data()
我已经从 github 页面上的示例中尝试过这段代码,但它似乎没有做任何事情。代码运行,但没有打印任何内容