#NEWLINE# def find_all_hid_devices( ) : #NEWLINE# #INDENT# 'Finds all HID devices connected to the system' #NEWLINE# guid = winapi . GetHidGuid ( ) #NEWLINE# results = [ ] #NEWLINE# required_size = DWORD ( ) #NEWLINE# info_data = winapi . SP_DEVINFO_DATA ( ) #NEWLINE# info_data . cb_size = sizeof ( winapi . SP_DEVINFO_DATA ) #NEWLINE# with winapi . DeviceInterfaceSetInfo ( guid ) as h_info : #NEWLINE# #INDENT# for interface_data in winapi . enum_device_interfaces ( h_info , guid ) : #NEWLINE# #INDENT# device_path = winapi . get_device_path ( h_info , interface_data , byref ( info_data ) ) #NEWLINE# parent_device = c_ulong ( ) #NEWLINE# if ( setup_api . CM_Get_Parent ( byref ( parent_device ) , info_data . dev_inst , 0 ) != 0 ) : #NEWLINE# #INDENT# parent_device . value = 0 #NEWLINE# #UNINDENT# required_size . value = 0 #NEWLINE# winapi . SetupDiGetDeviceInstanceId ( h_info , byref ( info_data ) , None , 0 , byref ( guid ) ) #NEWLINE# device_instance_id = create_unicode_buffer ( required_size . value ) #NEWLINE# if ( required_size . value > 0 ) : #NEWLINE# #INDENT# winapi . SetupDiGetDeviceInstanceId ( h_info , byref ( info_data ) , device_instance_id , required_size , byref ( required_size ) ) #NEWLINE# hid_device = HidDevice ( device_path , parent_device . value , device_instance_id . value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# hid_device = HidDevice ( device_path , parent_device . value ) #NEWLINE# #UNINDENT# if hid_device . vendor_id : #NEWLINE# #INDENT# results . append ( hid_device ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return results