当前位置: 首页>>代码示例>>Python>>正文


Python evdev.UInput类代码示例

本文整理汇总了Python中evdev.UInput的典型用法代码示例。如果您正苦于以下问题:Python UInput类的具体用法?Python UInput怎么用?Python UInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

class Input:
    def __init__(self):
        self._ui = UInput()

    def inject_event(self, keycode, typ):
	print "Injecting keycode: %s\n" % keycode
        self._ui.write(ecodes.EV_KEY, keycode, typ)
        self._ui.syn()
开发者ID:festlv,项目名称:carpc,代码行数:8,代码来源:serial_uinput.py

示例2: __init__

 def __init__(self):
     self.ui = UInput()
     cap = {e.EV_REL: [e.REL_X, e.REL_Y]}
     cap = {
         e.EV_REL : (e.REL_X, e.REL_Y),
         e.EV_KEY : (e.BTN_MOUSE,),
     }
     self.mouse = UInput(cap)
开发者ID:zteifel,项目名称:raspberry_remote,代码行数:8,代码来源:server_pyro.py

示例3: read_data

def read_data(ep_in):
    """
    Read the transmitted android keycodes from the input endpoint and trigger the corresponding key presses in linux.
    :param ep_in: input endpoint of the accessory device.
    """
    ui = UInput()
    while True:
        try:
            data = ep_in.read(3)
            keycode = data[1] * 0xFF + data[2]
            evdev_keycode = get_evdev_keycode(keycode)
            if data[0] == 0:
                print("Key down {}".format(keycode))
                if evdev_keycode != -1:
                    ui.write(ecodes.EV_KEY, evdev_keycode, 1)
                    ui.syn()
            elif data[0] == 1:
                print("Key up {}".format(keycode))
                if evdev_keycode != -1:
                    ui.write(ecodes.EV_KEY, evdev_keycode, 0)
                    ui.syn()
        except usb.core.USBError as e:
            # ignore exceptions caused by read timeout
            if e.errno == 110:
                pass
            else:
                print("failed to read input")
                print(e)
                break
开发者ID:WIStudent,项目名称:Android-Raspberry-Pi-Keyboard,代码行数:29,代码来源:accessory.py

示例4: __init__

class DeviceWriter:
    def __init__(self, scale):
        self.scale = scale
        # most values were taken from running
        # InputDevice('/dev/input/event$N').capabilities()
        vendor = 1133
        product = 0
        version = 273
        bustype = 3
        caps = {
            e.EV_KEY: [e.BTN_0, e.BTN_1],
            e.EV_REL: [e.REL_X, e.REL_Y, e.REL_Z, e.REL_RX, e.REL_RY, e.REL_RZ],
        }
        device_name = 'Virtual SpaceNav'
        self.state = True
        self.ui = UInput(caps, vendor=vendor, product=product,
                         version=version, bustype=bustype, name=device_name)

    def make_event(self, data):
        if not self.state:
            return
        for v in (data.linear, data.angular):
            # We don't want to write zeroes because the real spacenav never does,
            # instead write a small value inside Earth's gutter to prevent drift.
            if v.x == 0:
                v.x = 1.0 / self.scale
            if v.y == 0:
                v.y = 1.0 / self.scale
            if v.z == 0:
                v.z = 1.0 / self.scale
        # write some event to self.ui based off of the twist data
        _time = time.time()
        stime = int(_time)
        utime = int((float(_time) - stime) * 10 ** 6)
        x = InputEvent(stime, utime, e.EV_REL, e.REL_X, -self.translate(data.linear.y))
        y = InputEvent(stime, utime, e.EV_REL, e.REL_Y, -self.translate(data.linear.x))
        z = InputEvent(stime, utime, e.EV_REL, e.REL_Z, -self.translate(data.linear.z))
        ax = InputEvent(stime, utime, e.EV_REL, e.REL_RX, -self.translate(data.angular.y))
        ay = InputEvent(stime, utime, e.EV_REL, e.REL_RY, -self.translate(data.angular.x))
        az = InputEvent(stime, utime, e.EV_REL, e.REL_RZ, -self.translate(data.angular.z))
        # write all events
        self.ui.write_event(x)
        self.ui.write_event(y)
        self.ui.write_event(z)
        self.ui.write_event(ax)
        self.ui.write_event(ay)
        self.ui.write_event(az)
        # syn to alert input subsystem
        self.ui.syn()

    def translate(self, n):
        return int(n * self.scale)  # TODO find the translation...

    def set_state(self, msg):
        self.state = msg.state == ApplicationState.VISIBLE
开发者ID:EndPointCorp,项目名称:lg_ros_nodes,代码行数:55,代码来源:device_writer.py

示例5: create_device

    def create_device(self, layout):
        events = {ecodes.EV_ABS: [], ecodes.EV_KEY: [],
                  ecodes.EV_REL: []}

        # Joystick device
        if layout.axes or layout.buttons or layout.hats:
            self.joystick_dev = next_joystick_device()

        for name in layout.axes:
            key = getattr(ecodes, name)
            params = layout.axes_options.get(name, (0, 255, 0, 15))
            events[ecodes.EV_ABS].append((key, params))

        for name in layout.hats:
            key = getattr(ecodes, name)
            params = (-1, 1, 0, 0)
            events[ecodes.EV_ABS].append((key, params))

        for name in layout.buttons:
            events[ecodes.EV_KEY].append(getattr(ecodes, name))

        if layout.mouse:
            self.mouse_pos = {}
            for name in layout.mouse:
                events[ecodes.EV_REL].append(getattr(ecodes, name))

        self.device = UInput(name=layout.name, events=events,
                             bustype=layout.bustype, vendor=layout.vendor,
                             product=layout.product, version=layout.version)
        self.layout = layout
开发者ID:Vash63,项目名称:ds4drv,代码行数:30,代码来源:uinput.py

示例6: create_mouse

 def create_mouse(self):
     events = {
         ecodes.EV_REL: (ecodes.REL_X, ecodes.REL_Y),
         ecodes.EV_KEY: (ecodes.BTN_LEFT, ecodes.BTN_RIGHT)
     }
     self.mouse = UInput(events)
     self.mouse_pos = None
开发者ID:Tosta-Mixta,项目名称:ds4drv,代码行数:7,代码来源:ds4drv.py

示例7: create_device

    def create_device(self, layout):
        events = {ecodes.EV_ABS: [], ecodes.EV_KEY: [],
                  ecodes.EV_REL: []}

        # Joystick device
        if layout.axes or layout.buttons or layout.hats:
            self.joystick_dev = next_joystick_device()

        for name in layout.axes:
            params = layout.axes_options.get(name, DEFAULT_AXIS_OPTIONS)
            events[ecodes.EV_ABS].append((name, params))

        for name in layout.hats:
            params = (-1, 1, 0, 0)
            events[ecodes.EV_ABS].append((name, params))

        for name in layout.buttons:
            events[ecodes.EV_KEY].append(name)

        if layout.mouse:
            self.mouse_pos = {}
            self.mouse_rel = {}
            self.mouse_analog_sensitivity = float(layout.mouse_options.get("MOUSE_SENSITIVITY", 0.3))
            self.mouse_analog_deadzone = int(layout.mouse_options.get("MOUSE_DEADZONE", 5))

            for name in layout.mouse:
                events[ecodes.EV_REL].append(name)
                self.mouse_rel[name] = 0.0

        self.device = UInput(name=layout.name, events=events,
                             bustype=layout.bustype, vendor=layout.vendor,
                             product=layout.product, version=layout.version)
        self.layout = layout
开发者ID:tazjel,项目名称:ds4drv,代码行数:33,代码来源:uinput.py

示例8: __init__

 def __init__(self, n, m):
     Thread.__init__(self)
     self.n = n
     self.stop = False
     self.sleep = False
     self.ui = UInput()
     self.m = m
开发者ID:andredalton,项目名称:bcc,代码行数:7,代码来源:kmlogger.py

示例9: __init__

    def __init__(self, rate):
        """
        Parameters
        ----------
        rate : int
            sample rate
        """
        self._rate = float(rate)
        self._lf = None
        self._threshold = 15000
        self._last_edge = None
        self._ch = None

        # Size in sampling intervals, of the frame space marker
        self._marker = int(2.0 * 0.0025 * self._rate)

        # Mapping of channels to events
        self._mapping = {0: ecodes.ABS_X,
                         1: ecodes.ABS_Y,
                         2: ecodes.ABS_Z,
                         3: ecodes.ABS_THROTTLE}

        events = [(v, (0, 255, 5, 0)) for v in self._mapping.values()]

        self._ev = UInput(name='ppmadapter',
                          events={
                               ecodes.EV_ABS: events,
                               ecodes.EV_KEY: {288: 'BTN_JOYSTICK'}
                          })
开发者ID:nigelsim,项目名称:ppmadapter,代码行数:29,代码来源:__init__.py

示例10: _prepare_device

    def _prepare_device (self):
        #print("device: %s" % self._profile.device.name)
        self._event_status = {key:0 for key in self._profile.device.get_events_supported()}
        #print("Events supported",self._event_status)
        self._allowed_event_types = set([getattr(ecodes,i[-1].split(':')[0]) for i in self._event_status])
        self._input_devices = map(InputDevice, self._profile.device.devices)
        self._file_descriptors = { dev.fd: i for i, dev in enumerate(self._input_devices) }
        
        print("Mappings for '" + self._profile.name+"' " + '-'*30)
        for k,v in sorted(self._profile.mapping.items()):
            print(str(k.replace("EV_KEY:KEY_","").replace("ENTER","<-'").replace("APOSTROPHE","'").replace(",","")).lower().rjust(20)+" as "+(', '.join(v)).replace("r_hand_tap_", "").replace("_vs_thumb", ""))
            
        # Prepare virtual device for event injection
        capabilities = {}
        for ev_chain in self._profile.mapping:
            for k in re.split('[+,]', ev_chain):
                et, ec = k.split(':', 1)
                etype = ecodes.ecodes[et]
                if etype in capabilities:
                    capabilities[etype].append(ecodes.ecodes[ec])
                else:
                    capabilities[etype] = [ ecodes.ecodes[ec] ]
        #print("Capabilities", capabilities)
        self._virtual_input = UInput(events = capabilities)

        # Prepare matcher
        self._matcher = Matcher(self._profile)
开发者ID:gcobos,项目名称:hidmapper,代码行数:27,代码来源:controller.py

示例11: writeWord

def writeWord(word):
    listOfLetters = list(word)
    
    
    ui = UInput()
    
    for letter in listOfLetters:
        if letter.isupper():
            letter = letter.lower()
            case = 'upper'
        else:
            case = 'lower'

        writeUiCase(letter, ui, case)

    ui.syn()
    ui.close()
开发者ID:BuFuuu,项目名称:autocompletion_linux,代码行数:17,代码来源:doInput.py

示例12: executaAcao

def executaAcao(tecla):
        ui = UInput()
        print tecla
        ui.write(e.EV_KEY, e.ecodes[tecla], 1) #key down
        ui.write(e.EV_KEY, e.ecodes[tecla], 0) #key up
        ui.syn()
        ui.close()
开发者ID:joaoluizdhv,项目名称:controlearduino,代码行数:7,代码来源:controle.py

示例13: create_device

    def create_device(self, layout):
        """Creates a uinput device using the specified layout."""
        events = {ecodes.EV_ABS: [], ecodes.EV_KEY: [],
                  ecodes.EV_REL: []}

        # Joystick device
        if layout.axes or layout.buttons or layout.hats:
            self.joystick_dev = next_joystick_device()

        for name in layout.axes:
            params = layout.axes_options.get(name, DEFAULT_AXIS_OPTIONS)
            if not absInfoUsesValue:
                params = params[1:]
            events[ecodes.EV_ABS].append((name, params))

        for name in layout.hats:
            params = (0, -1, 1, 0, 0)
            if not absInfoUsesValue:
                params = params[1:]
            events[ecodes.EV_ABS].append((name, params))

        for name in layout.buttons:
            events[ecodes.EV_KEY].append(name)

        if layout.mouse:
            self.mouse_pos = {}
            self.mouse_rel = {}
            self.mouse_analog_sensitivity = float(
                layout.mouse_options.get("MOUSE_SENSITIVITY",
                                         DEFAULT_MOUSE_SENSITIVTY)
            )
            self.mouse_analog_deadzone = int(
                layout.mouse_options.get("MOUSE_DEADZONE",
                                         DEFAULT_MOUSE_DEADZONE)
            )
            self.scroll_repeat_delay = float(
                layout.mouse_options.get("MOUSE_SCROLL_REPEAT_DELAY",
                                         DEFAULT_SCROLL_REPEAT_DELAY)
            )
            self.scroll_delay = float(
                layout.mouse_options.get("MOUSE_SCROLL_DELAY",
                                         DEFAULT_SCROLL_DELAY)
            )

            for name in layout.mouse:
                if name in (ecodes.REL_WHEELUP, ecodes.REL_WHEELDOWN):
                    if ecodes.REL_WHEEL not in events[ecodes.EV_REL]:
                        # This ensures that scroll wheel events can work
                        events[ecodes.EV_REL].append(ecodes.REL_WHEEL)
                else:
                    events[ecodes.EV_REL].append(name)
                self.mouse_rel[name] = 0.0

        self.device = UInput(name=layout.name, events=events,
                             bustype=layout.bustype, vendor=layout.vendor,
                             product=layout.product, version=layout.version)
        self.layout = layout
开发者ID:chrippa,项目名称:ds4drv,代码行数:57,代码来源:uinput.py

示例14: __init__

 def __init__(self, listener=MouseListener()):
     Thread.__init__(self)
     self.m = PyMouse()
     self.ui = UInput()
     self.devices = []
     self.running = True
     self.lastPosition = None
     self.device_search()
     self.listener = listener
开发者ID:andredalton,项目名称:kmlogger,代码行数:9,代码来源:mouse.py

示例15: execute

    def execute(self):
        print "Executing " + e.KEY[self.macroKey] + " macro."
        ui = UInput()

        for i in range(len(self.keySequence)):
            ui.write(e.EV_KEY, self.keySequence[i], self.keyState[i]);
        ui.syn()
        ui.close()
开发者ID:wassonan,项目名称:macro,代码行数:8,代码来源:macro.py


注:本文中的evdev.UInput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。