示例#1
0
    def __init__(self,
                 events=None,
                 name='py-evdev-uinput',
                 vendor=0x1,
                 product=0x1,
                 version=0x1,
                 bustype=0x3,
                 devnode='/dev/uinput',
                 phys='py-evdev-uinput'):
        '''
        Arguments
        ---------
        events : dict
          Dictionary of event types mapping to lists of event codes. The
          event types and codes that the uinput device will be able to
          inject - defaults to all key codes.

        name
          The name of the input device.

        vendor
          Vendor identifier.

        product
          Product identifier.

        version
          version identifier.

        bustype
          bustype identifier.

        phys
          physical path.
          
        Note
        ----
        If you do not specify any events, the uinput device will be able
        to inject only ``KEY_*`` and ``BTN_*`` event codes.
        '''

        self.name = name  #: Uinput device name.
        self.vendor = vendor  #: Device vendor identifier.
        self.product = product  #: Device product identifier.
        self.version = version  #: Device version identifier.
        self.bustype = bustype  #: Device bustype - e.g. ``BUS_USB``.
        self.phys = phys  #: Uinput device physical path.
        self.devnode = devnode  #: Uinput device node - e.g. ``/dev/uinput/``.

        if not events:
            events = {ecodes.EV_KEY: ecodes.keys.keys()}

        # The min, max, fuzz and flat values for the absolute axis for
        # a given code.
        absinfo = []

        self._verify()

        #: Write-only, non-blocking file descriptor to the uinput device node.
        self.fd = _uinput.open(devnode)

        # Set phys name
        _uinput.set_phys(self.fd, phys)

        # Set device capabilities.
        for etype, codes in events.items():
            for code in codes:
                # Handle max, min, fuzz, flat.
                if isinstance(code, (tuple, list, device.AbsInfo)):
                    # Flatten (ABS_Y, (0, 255, 0, 0, 0, 0)) to (ABS_Y, 0, 255, 0, 0, 0, 0).
                    f = [code[0]]
                    f += code[1]
                    absinfo.append(f)
                    code = code[0]

                # TODO: a lot of unnecessary packing/unpacking
                _uinput.enable(self.fd, etype, code)

        # Create the uinput device.
        _uinput.create(self.fd, name, vendor, product, version, bustype,
                       absinfo)

        #: An :class:`InputDevice <evdev.device.InputDevice>` instance
        #: for the fake input device. ``None`` if the device cannot be
        #: opened for reading and writing.
        self.device = self._find_device()
示例#2
0
    def __init__(self,
                 events=None,
                 name='py-evdev-uinput',
                 vendor=0x1, product=0x1, version=0x1, bustype=0x3,
                 devnode='/dev/uinput'):
        '''
        :param events: the event types and codes that the uinput
                       device will be able to inject - defaults to all
                       key codes.

        :type events: dictionary of event types mapping to lists of
                      event codes.

        :param name:    the name of the input device.
        :param vendor:  vendor identifier.
        :param product: product identifier.
        :param version: version identifier.
        :param bustype: bustype identifier.

        .. note:: If you do not specify any events, the uinput device
                  will be able to inject only ``KEY_*`` and ``BTN_*``
                  event codes.
        '''

        self.name = name         #: Uinput device name.
        self.vendor = vendor     #: Device vendor identifier.
        self.product = product   #: Device product identifier.
        self.version = version   #: Device version identifier.
        self.bustype = bustype   #: Device bustype - eg. ``BUS_USB``.
        self.devnode = devnode   #: Uinput device node - eg. ``/dev/uinput/``.

        if not events:
            events = {ecodes.EV_KEY: ecodes.keys.keys()}

        # the min, max, fuzz and flat values for the absolute axis for
        # a given code
        absinfo = []

        self._verify()

        #: Write-only, non-blocking file descriptor to the uinput device node.
        self.fd = _uinput.open(devnode)

        # set device capabilities
        for etype, codes in events.items():
            for code in codes:
                # handle max, min, fuzz, flat
                if isinstance(code, (tuple, list, device.AbsInfo)):
                    # flatten (ABS_Y, (0, 255, 0, 0)) to (ABS_Y, 0, 255, 0, 0)
                    f = [code[0]]; f += code[1]
                    absinfo.append(f)
                    code = code[0]

                #:todo: a lot of unnecessary packing/unpacking
                _uinput.enable(self.fd, etype, code)

        # create uinput device
        _uinput.create(self.fd, name, vendor, product, version, bustype, absinfo)

        #: An :class:`InputDevice <evdev.device.InputDevice>` instance
        #: for the fake input device. ``None`` if the device cannot be
        #: opened for reading and writing.
        self.device = self._find_device()
示例#3
0
    def __init__(self,
                 events=None,
                 name='py-evdev-uinput',
                 vendor=0x1,
                 product=0x1,
                 version=0x1,
                 bustype=0x3,
                 devnode='/dev/uinput'):
        '''

        :param events: the event types and codes that the uinput
                       device will be able to inject - defaults to all
                       key codes.

        :type events: dictionary of event types mapping to lists of
                      event codes

        :param name: the name of the input device
        :param vendor:  vendor identifier
        :param product: product identifier
        :param version: version identifier
        :param bustype: bustype identifier

        .. note:: If you do not specify any events, the uinput device
                  will by default be able to inject only KEY_* and
                  BTN_* event codes.

        '''

        self.name = name  #: uinput device name
        self.vendor = vendor  #: device vendor identifier
        self.product = product  #: device product identifier
        self.version = version  #: device version identifier
        self.bustype = bustype  #: device bustype - eg. ``BUS_USB``
        self.devnode = devnode  #: uinput device node - eg. ``/dev/uinput/``

        if not events:
            events = {ecodes.EV_KEY: ecodes.keys.keys()}

        # the min, max, fuzz and flat values for the absolute axis for
        # a given code
        absinfo = []

        self._verify()

        #: open write-only, nonblocking file descriptor to the uinput devnode
        self.fd = _uinput.open(devnode)

        # set device capabilities
        for etype, codes in events.items():
            for code in codes:
                # handle max,min,fuzz,flat
                if isinstance(code, (tuple, list, device.AbsInfo)):
                    # flatten (ABS_Y, (0,255,0,0)) to (ABS_Y,0,255,0,0)
                    f = [code[0]]
                    f += code[1]
                    absinfo.append(f)
                    code = code[0]

                #:todo: a lot of unnecessary packing/unpacking
                _uinput.enable(self.fd, etype, code)

        # create uinput device
        _uinput.create(self.fd, name, vendor, product, version, bustype,
                       absinfo)

        #: an :class:`InputDevice <evdev.device.InputDevice>` instance
        # to the fake input device
        self.device = self._find_device()
示例#4
0
    def __init__(self,
                 events=None,
                 name='py-evdev-uinput',
                 vendor=0x1,
                 product=0x1,
                 version=0x1,
                 bustype=0x3,
                 devnode='/dev/uinput',
                 phys='py-evdev-uinput',
                 input_props=None):
        '''
        Arguments
        ---------
        events : dict
          Dictionary of event types mapping to lists of event codes. The
          event types and codes that the uinput device will be able to
          inject - defaults to all key codes.

        name
          The name of the input device.

        vendor
          Vendor identifier.

        product
          Product identifier.

        version
          Version identifier.

        bustype
          Bustype identifier.

        phys
          Physical path.

        input_props
          Input properties and quirks.

        Note
        ----
        If you do not specify any events, the uinput device will be able
        to inject only ``KEY_*`` and ``BTN_*`` event codes.
        '''

        self.name = name  #: Uinput device name.
        self.vendor = vendor  #: Device vendor identifier.
        self.product = product  #: Device product identifier.
        self.version = version  #: Device version identifier.
        self.bustype = bustype  #: Device bustype - e.g. ``BUS_USB``.
        self.phys = phys  #: Uinput device physical path.
        self.devnode = devnode  #: Uinput device node - e.g. ``/dev/uinput/``.

        if not events:
            events = {ecodes.EV_KEY: ecodes.keys.keys()}

        self._verify()

        #: Write-only, non-blocking file descriptor to the uinput device node.
        self.fd = _uinput.open(devnode)

        # Prepare the list of events for passing to _uinput.enable and _uinput.setup.
        absinfo, prepared_events = self._prepare_events(events)

        # Set phys name
        _uinput.set_phys(self.fd, phys)

        # Set properties
        input_props = input_props or []
        for prop in input_props:
            _uinput.set_prop(self.fd, prop)

        for etype, code in prepared_events:
            _uinput.enable(self.fd, etype, code)

        _uinput.setup(self.fd, name, vendor, product, version, bustype,
                      absinfo)

        # Create the uinput device.
        _uinput.create(self.fd)

        self.dll = ctypes.CDLL(_uinput.__file__)
        self.dll._uinput_begin_upload.restype = ctypes.c_int
        self.dll._uinput_end_upload.restype = ctypes.c_int

        #: An :class:`InputDevice <evdev.device.InputDevice>` instance
        #: for the fake input device. ``None`` if the device cannot be
        #: opened for reading and writing.
        self.device = self._find_device()
示例#5
0
    def __init__(self,
                 events=None,
                 name='py-evdev-uinput',
                 vendor=0x1, product=0x1, version=0x1, bustype=0x3,
                 devnode='/dev/uinput', phys='py-evdev-uinput'):
        '''
        Arguments
        ---------
        events : dict
          Dictionary of event types mapping to lists of event codes. The
          event types and codes that the uinput device will be able to
          inject - defaults to all key codes.

        name
          The name of the input device.

        vendor
          Vendor identifier.

        product
          Product identifier.

        version
          version identifier.

        bustype
          bustype identifier.

        phys
          physical path.

        Note
        ----
        If you do not specify any events, the uinput device will be able
        to inject only ``KEY_*`` and ``BTN_*`` event codes.
        '''

        self.name = name         #: Uinput device name.
        self.vendor = vendor     #: Device vendor identifier.
        self.product = product   #: Device product identifier.
        self.version = version   #: Device version identifier.
        self.bustype = bustype   #: Device bustype - e.g. ``BUS_USB``.
        self.phys    = phys      #: Uinput device physical path.
        self.devnode = devnode   #: Uinput device node - e.g. ``/dev/uinput/``.

        if not events:
            events = {ecodes.EV_KEY: ecodes.keys.keys()}

        self._verify()

        #: Write-only, non-blocking file descriptor to the uinput device node.
        self.fd = _uinput.open(devnode)

        # Prepare the list of events for passing to _uinput.enable and _uinput.setup.
        absinfo, prepared_events = self._prepare_events(events)

        # Set phys name
        _uinput.set_phys(self.fd, phys)

        for etype, code in prepared_events:
            _uinput.enable(self.fd, etype, code)

        _uinput.setup(self.fd, name, vendor, product, version, bustype, absinfo)

        # Create the uinput device.
        _uinput.create(self.fd)

        self.dll = ctypes.CDLL(_uinput.__file__)
        self.dll._uinput_begin_upload.restype = ctypes.c_int
        self.dll._uinput_end_upload.restype = ctypes.c_int

        #: An :class:`InputDevice <evdev.device.InputDevice>` instance
        #: for the fake input device. ``None`` if the device cannot be
        #: opened for reading and writing.
        self.device = self._find_device()