def print_devices():
    """
    Simple test function which prints out all devices found by evdev
    """

    def device_verbose_info(device: InputDevice) -> {}:
        """
        Gather and format as much info as possible about the supplied InputDevice. Used mostly for debugging at this point.

        :param device:
            An InputDevice to examine
        :return:
            A dict containing as much information as possible about the input device.
        """

        def axis_name(axis_code):
            try:
                return ecodes.ABS[axis_code]
            except KeyError:
                return 'EXTENDED_CODE_{}'.format(axis_code)

        def rel_axis_name(axis_code):
            try:
                return ecodes.REL[axis_code]
            except KeyError:
                return 'EXTENDED_CODE_{}'.format(axis_code)

        axes = None
        if has_abs_axes(device):
            axes = {
                axis_name(axis_code): {'code': axis_code, 'min': axis_info.min, 'max': axis_info.max,
                                       'fuzz': axis_info.fuzz,
                                       'flat': axis_info.flat, 'res': axis_info.resolution} for
                axis_code, axis_info in device.capabilities().get(3)}

        rel_axes = None
        if has_rel_axes(device):
            print(device.capabilities().get(2))
            rel_axes = {
                rel_axis_name(axis_code): {'code': axis_code} for
                axis_code in device.capabilities().get(2)}

        buttons = None
        if has_buttons(device):
            buttons = {code: names for (names, code) in
                       dict(util.resolve_ecodes_dict({1: device.capabilities().get(1)})).get(('EV_KEY', 1))}

        return {'fn': device.fn, 'path': device.path, 'name': device.name, 'phys': device.phys, 'uniq': device.uniq,
                'vendor': device.info.vendor, 'product': device.info.product, 'version': device.info.version,
                'bus': device.info.bustype, 'axes': axes, 'rel_axes': rel_axes, 'buttons': buttons,
                'unique_name': unique_name(device)}

    def has_abs_axes(device):
        return device.capabilities().get(3) is not None

    def has_rel_axes(device):
        return device.capabilities().get(2) is not None

    def has_buttons(device):
        return device.capabilities().get(1) is not None

    _check_import()
    for d in [InputDevice(fn) for fn in list_devices()]:
        if has_abs_axes(d) or has_rel_axes(d):
            pp = pprint.PrettyPrinter(indent=2, width=100)
            pp.pprint(device_verbose_info(d))
def print_devices ( ) : def device_verbose_info ( device : InputDevice ) -> { } : def axis_name ( axis_code ) : try : return ecodes . ABS [ axis_code ] except KeyError : return 'EXTENDED_CODE_{}' . format ( axis_code ) def rel_axis_name ( axis_code ) : try : return ecodes . REL [ axis_code ] except KeyError : return 'EXTENDED_CODE_{}' . format ( axis_code ) axes = None if has_abs_axes ( device ) : axes = { axis_name ( axis_code ) : { 'code' : axis_code , 'min' : axis_info . min , 'max' : axis_info . max , 'fuzz' : axis_info . fuzz , 'flat' : axis_info . flat , 'res' : axis_info . resolution } for axis_code , axis_info in device . capabilities ( ) . get ( 3 ) } rel_axes = None if has_rel_axes ( device ) : print ( device . capabilities ( ) . get ( 2 ) ) rel_axes = { rel_axis_name ( axis_code ) : { 'code' : axis_code } for axis_code in device . capabilities ( ) . get ( 2 ) } buttons = None if has_buttons ( device ) : buttons = { code : names for ( names , code ) in dict ( util . resolve_ecodes_dict ( { 1 : device . capabilities ( ) . get ( 1 ) } ) ) . get ( ( 'EV_KEY' , 1 ) ) } return { 'fn' : device . fn , 'path' : device . path , 'name' : device . name , 'phys' : device . phys , 'uniq' : device . uniq , 'vendor' : device . info . vendor , 'product' : device . info . product , 'version' : device . info . version , 'bus' : device . info . bustype , 'axes' : axes , 'rel_axes' : rel_axes , 'buttons' : buttons , 'unique_name' : unique_name ( device ) } def has_abs_axes ( device ) : return device . capabilities ( ) . get ( 3 ) is not None def has_rel_axes ( device ) : return device . capabilities ( ) . get ( 2 ) is not None def has_buttons ( device ) : return device . capabilities ( ) . get ( 1 ) is not None _check_import ( ) for d in [ InputDevice ( fn ) for fn in list_devices ( ) ] : if has_abs_axes ( d ) or has_rel_axes ( d ) : pp = pprint . PrettyPrinter ( indent = 2 , width = 100 ) pp . pprint ( device_verbose_info ( d ) )
Simple test function which prints out all devices found by evdev