pub fn produce_raw_device_list(incl_360_devices: bool) -> Devices {
    let mut device_list = Devices::new();
    unsafe {
        let mut buffer: [RAWINPUTDEVICELIST; 1000] = MaybeUninit::uninit().assume_init();
        let mut num_devices: UINT = 0;
        let device_list_size = mem::size_of::<RAWINPUTDEVICELIST>();
        let mut result =
            GetRawInputDeviceList(ptr::null_mut(), &mut num_devices, device_list_size as UINT);
        if result == -1i32 as UINT {
            panic!("Failed to Get Raw Device List!");
        }
        result = GetRawInputDeviceList(
            buffer.as_mut_ptr() as PRAWINPUTDEVICELIST,
            &mut num_devices,
            device_list_size as UINT,
        );
        if result == -1i32 as UINT {
            panic!("Failed to Get Raw Device List!");
        }

        for pos in 0..result as usize {
            let device_ptr = (&mut buffer[pos..(pos + 1)]).as_mut_ptr() as PRAWINPUTDEVICELIST;
            let device = *device_ptr;
            let device_handle = device.hDevice;
            let device_type = device.dwType;
            let name = raw_handle_to_name(device_handle);
            let hid_handle = match raw_name_to_hid(name.clone()) {
                Ok(handle) => handle,
                Err(_) => continue,
            };
            let serial = get_serial_number(hid_handle);
            let device_info_option = get_device_info(device_handle, name, serial);
            match device_info_option {
                None => continue,
                _ => (),
            }
            let device_info = device_info_option.unwrap();
            match device_type {
                RIM_TYPEMOUSE => {
                    if let DeviceInfo::Mouse(info) = device_info {
                        device_list
                            .device_map
                            .insert(device_handle, device_list.mice.len());
                        device_list.mice.push(info);
                    } else {
                        panic!("Unreachable!");
                    }
                }
                RIM_TYPEKEYBOARD => {
                    if let DeviceInfo::Keyboard(info) = device_info {
                        device_list
                            .device_map
                            .insert(device_handle, device_list.keyboards.len());
                        device_list.keyboards.push(info);
                    } else {
                        panic!("Unreachable!");
                    }
                }
                RIM_TYPEHID => {
                    if let DeviceInfo::Joystick(info) = device_info {
                        if info.is_360_controller && !incl_360_devices {
                            continue;
                        }
                        device_list
                            .device_map
                            .insert(device_handle, device_list.joysticks.len());
                        device_list.joysticks.push(info);
                    } else {
                        panic!("Unreachable!");
                    }
                }
                _ => (),
            }
        }
    }
    device_list.original_device_map = device_list.device_map.clone();
    device_list
}
/// Produces a Device struct containing ID's to all available raw input Devices

Produces a Device struct containing ID's to all available raw input Devices
Produces a Device struct containing ID ' s to all available raw input Devices
pub fn produce_raw_device_list(incl_360_devices: bool) -> Devices {
    let mut device_list = Devices::new();
    unsafe {
        let mut buffer: [RAWINPUTDEVICELIST; 1000] = MaybeUninit::uninit().assume_init();
        let mut num_devices: UINT = 0;
        let device_list_size = mem::size_of::<RAWINPUTDEVICELIST>();
        let mut result =
            GetRawInputDeviceList(ptr::null_mut(), &mut num_devices, device_list_size as UINT);
        if result == -1i32 as UINT {
            panic!("Failed to Get Raw Device List!");
        }
        result = GetRawInputDeviceList(
            buffer.as_mut_ptr() as PRAWINPUTDEVICELIST,
            &mut num_devices,
            device_list_size as UINT,
        );
        if result == -1i32 as UINT {
            panic!("Failed to Get Raw Device List!");
        }
        for pos in 0..result as usize {
            let device_ptr = (&mut buffer[pos..(pos + 1)]).as_mut_ptr() as PRAWINPUTDEVICELIST;
            let device = *device_ptr;
            let device_handle = device.hDevice;
            let device_type = device.dwType;
            let name = raw_handle_to_name(device_handle);
            let hid_handle = match raw_name_to_hid(name.clone()) {
                Ok(handle) => handle,
                Err(_) => continue,
            };
            let serial = get_serial_number(hid_handle);
            let device_info_option = get_device_info(device_handle, name, serial);
            match device_info_option {
                None => continue,
                _ => (),
            }
            let device_info = device_info_option.unwrap();
            match device_type {
                RIM_TYPEMOUSE => {
                    if let DeviceInfo::Mouse(info) = device_info {
                        device_list
                            .device_map
                            .insert(device_handle, device_list.mice.len());
                        device_list.mice.push(info);
                    } else {
                        panic!("Unreachable!");
                    }
                }
                RIM_TYPEKEYBOARD => {
                    if let DeviceInfo::Keyboard(info) = device_info {
                        device_list
                            .device_map
                            .insert(device_handle, device_list.keyboards.len());
                        device_list.keyboards.push(info);
                    } else {
                        panic!("Unreachable!");
                    }
                }
                RIM_TYPEHID => {
                    if let DeviceInfo::Joystick(info) = device_info {
                        if info.is_360_controller && !incl_360_devices {
                            continue;
                        }
                        device_list
                            .device_map
                            .insert(device_handle, device_list.joysticks.len());
                        device_list.joysticks.push(info);
                    } else {
                        panic!("Unreachable!");
                    }
                }
                _ => (),
            }
        }
    }
    device_list.original_device_map = device_list.device_map.clone();
    device_list
}
pub fn produce_raw_device_list ( incl_360_devices : bool ) -> Devices { let mut device_list = Devices :: new ( ) ; unsafe { let mut buffer : [ RAWINPUTDEVICELIST ; 1000 ] = MaybeUninit :: uninit ( ) . assume_init ( ) ; let mut num_devices : UINT = 0 ; let device_list_size = mem :: size_of :: < RAWINPUTDEVICELIST > ( ) ; let mut result = GetRawInputDeviceList ( ptr :: null_mut ( ) , & mut num_devices , device_list_size as UINT ) ; if result == - 1i32 as UINT { panic ! ( " " ) ; } result = GetRawInputDeviceList ( buffer . as_mut_ptr ( ) as PRAWINPUTDEVICELIST , & mut num_devices , device_list_size as UINT , ) ; if result == - 1i32 as UINT { panic ! ( " " ) ; } for pos in 0 .. result as usize { let device_ptr = ( & mut buffer [ pos .. ( pos + 1 ) ] ) . as_mut_ptr ( ) as PRAWINPUTDEVICELIST ; let device = * device_ptr ; let device_handle = device . hDevice ; let device_type = device . dwType ; let name = raw_handle_to_name ( device_handle ) ; let hid_handle = match raw_name_to_hid ( name . clone ( ) ) { Ok ( handle ) => handle , Err ( _ ) => continue , } ; let serial = get_serial_number ( hid_handle ) ; let device_info_option = get_device_info ( device_handle , name , serial ) ; match device_info_option { None => continue , _ => ( ) , } let device_info = device_info_option . unwrap ( ) ; match device_type { RIM_TYPEMOUSE => { if let DeviceInfo :: Mouse ( info ) = device_info { device_list . device_map . insert ( device_handle , device_list . mice . len ( ) ) ; device_list . mice . push ( info ) ; } else { panic ! ( " " ) ; } } RIM_TYPEKEYBOARD => { if let DeviceInfo :: Keyboard ( info ) = device_info { device_list . device_map . insert ( device_handle , device_list . keyboards . len ( ) ) ; device_list . keyboards . push ( info ) ; } else { panic ! ( " " ) ; } } RIM_TYPEHID => { if let DeviceInfo :: Joystick ( info ) = device_info { if info . is_360_controller && ! incl_360_devices { continue ; } device_list . device_map . insert ( device_handle , device_list . joysticks . len ( ) ) ; device_list . joysticks . push ( info ) ; } else { panic ! ( " " ) ; } } _ => ( ) , } } } device_list . original_device_map = device_list . device_map . clone ( ) ; device_list }
Produces a Device struct containing ID's to all available raw input Devices
Produces a Device struct containing ID ' s to all available raw input Devices
incl_360_devices
bool
incl_360_devices
bool