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


Python evdev.categorize方法代码示例

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


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

示例1: _evdev_callback

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def _evdev_callback(self, device):
        async for event in device.async_read_loop():
            try:
                if not self._opened:
                    return

                if event.type == evdev.ecodes.EV_KEY:
                    ev = evdev.categorize(event)

                    for callback in self._event_callbacks:
                        await callback(ev)

                if not self._opened:
                    return

            except (OSError, IOError) as err:
                self._logger.exception("Event device error", exc_info=err)
                break 
开发者ID:cyanogen,项目名称:uchroma,代码行数:20,代码来源:input.py

示例2: RequestPasskey

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def RequestPasskey(self, device):
        print("RequestPasskey (%s)" % (device))
        passkey = ""
        kb = ev.InputDevice(glob.glob('/dev/input/by-path/*event-kbd')[0])
        print(kb)
        for event in kb.read_loop():
            data = ev.categorize(event)
            if event.type != ev.ecodes.EV_KEY:
                continue
            elif data.keystate == 0: # ignore keyup
                continue

            key = ev.ecodes.KEY[event.code][4:]
            if key == 'ENTER': # we are done
                break
            elif key in ['1','2','3','4','5','6','7','8','9','0']:
                passkey = passkey + key

        set_trusted(device)
        return int(passkey) 
开发者ID:lvht,项目名称:btk,代码行数:22,代码来源:agent.py

示例3: read_input

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def read_input(self):
        """Listens solely to the RFID keyboard and returns the scanned badge.

        Args:
          device: input device to listen to

        Returns:
          badge value as string
        """

        rfid = ""
        capitalized = 0
        device = self.f
        print("About to read_input")
        for event in device.read_loop():
            # print("read_input event", event)
            data = evdev.categorize(event)
            if event.type == evdev.ecodes.EV_KEY and data.keystate == 1:
                if data.scancode == self.LSHIFT_SCANCODE:
                    capitalized = 1
                if data.keycode == "KEY_ENTER":
                    break
                if data.scancode != self.LSHIFT_SCANCODE:
                    if capitalized:
                        rfid += self.capscancodes[data.scancode]
                        capitalized ^= 1
                    else:
                        rfid += self.scancodes[data.scancode]
        print("Badge read:", rfid)
        return rfid 
开发者ID:google,项目名称:makerspace-auth,代码行数:32,代码来源:badgereader_hid_keystroking.py

示例4: run

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def run(self):
        for event in self.device.read_loop():
           evc = evdev.categorize(event)
           if isinstance(evc, evdev.AbsEvent):
               self._pending[event.code] = event.value
           elif isinstance(evc, evdev.KeyEvent):
               self.onKey(evc)
           elif isinstance(evc, evdev.SynEvent):
               for axis, value in self._pending.items():
                   self.axes[axis][1][0] = value
               self._pendingValues = {} 
开发者ID:scanlime,项目名称:fygimbal,代码行数:13,代码来源:tinyjoy.py

示例5: reader_thread

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def reader_thread(self):
        # A mapping of file descriptors (integers) to InputDevice instances.
        devices = {dev.fd: dev for dev in self.devices}

        while True:
            r, w, x = select(devices, [], [])
            for fd in r:
                for event in devices[fd].read():
                    ce = evdev.categorize(event)
                    if isinstance(ce, evdev.KeyEvent):
                        self.handle_key(ce.keycode, ce.keystate)

        return 
开发者ID:swehner,项目名称:foos,代码行数:15,代码来源:io_evdev_keyboard.py

示例6: read_events

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def read_events(req_device):
    for device in list_devices():
        # Look in all 3 identifiers + event number
        if req_device in device or \
           req_device == device[0].replace("/dev/input/event", ""):
            found = evdev.InputDevice(device[0])

    if 'found' not in locals():
        print("Device not found. \n"
              "Please use --list-devices to view a list of available devices.")
        return

    print(found)
    print("To stop, press Ctrl-C")

    for event in found.read_loop():
        try:
            if event.type == evdev.ecodes.EV_KEY:
                categorized = evdev.categorize(event)
                if categorized.keystate == 1:
                    keycode = categorized.keycode if type(categorized.keycode) is str \
                        else " | ".join(categorized.keycode)
                    print("Key pressed: %s (%s)" % (keycode, categorized.scancode))
        except KeyError:
            if event.value:
                print("Unknown key (%s) has been pressed." % event.code)
            else:
                print("Unknown key (%s) has been released." % event.code) 
开发者ID:philipl,项目名称:evdevremapkeys,代码行数:30,代码来源:evdevremapkeys.py

示例7: listen_for_events

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def listen_for_events(dev):
    for event in dev.read_loop():
        if event.type == ecodes.EV_KEY:
            print dev.name+":  "+str(categorize(event)) 
开发者ID:CRImier,项目名称:pyLCI,代码行数:6,代码来源:debug_listener.py

示例8: handle_event

# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import categorize [as 别名]
def handle_event(device, myMQTTClient):
    async for event in device.async_read_loop():
        for num, joystick in enumerate(joysticks):
            if joystick['device']==device:
                jsindex = num
        categorized = categorize(event)
        if event.type == ecodes.EV_KEY:
            logging.debug(f'button push {joysticks[jsindex]["color"]} {joysticks[jsindex]["path"]}: {categorized.keycode}, {categorized.keystate}')
            logging.info(f'move {joysticks[jsindex]["move"]} locked {joysticks[jsindex]["movelocked"]}')
            if (categorized.keycode[0] == KEY_JOYSTICK or categorized.keycode[0]
                == KEY_BTNA) and categorized.keystate == 1 and not (
                joysticks[jsindex]['move'] == '') and not (
                joysticks[jsindex]['movelocked'] == True):
                #submit move if there is one
                logging.debug(f'move submitted for {joysticks[jsindex]["color"]}, {joysticks[jsindex]["device"]}:{joysticks[jsindex]["move"]}')
                joysticks[jsindex]['movelocked']=True
                message = {}
                message['joystick']=joysticks[jsindex]['color']
                message['move']=joysticks[jsindex]['move']
                jsonmsg = json.dumps(message)
                topic = joysticks[jsindex]['movetopic']
                myMQTTClient.publish(topic, jsonmsg, 0)
                logging.info(f'posted move {jsonmsg}')
                await setLightStatus(jsindex, MOVE_LOCKED)
            elif (categorized.keycode==KEY_THUMB or categorized.keycode==KEY_TL2
                ) and categorized.keystate==1:
                #for debugging, clear move
                joysticks[jsindex]['move'] = ''
                joysticks[jsindex]['movelocked']=False
                await setLightStatus(jsindex, READY_FOR_MOVES)
                logging.info(f'{joysticks[jsindex]["color"]} {joysticks[jsindex]["path"]} unlocked')
                logging.info(f'{joysticks}')
        elif event.type == ecodes.EV_ABS and joysticks[jsindex]['movelocked']==False and (
            event.value == ABS_LEFT or event.value==ABS_RIGHT):
            logging.debug(f'joystick move {joysticks[jsindex]["move"]} {joysticks[jsindex]["path"]} value: {event.value} {event}')
            if event.code == ABS_X:
                if event.value == ABS_RIGHT:
                    joysticks[jsindex]['move'] = MOVE_RIGHT
                    logging.info(f'{joysticks[jsindex]["color"]} {joysticks[jsindex]["path"]} right')
                elif event.value == ABS_LEFT:
                    joysticks[jsindex]['move'] = MOVE_LEFT
                    logging.info(f'{joysticks[jsindex]["color"]} {joysticks[jsindex]["path"]} left')
            elif event.code == ABS_Y:
                if event.value == ABS_UP:
                    joysticks[jsindex]['move'] = MOVE_FORWARD
                    logging.info(f'{joysticks[jsindex]["color"]} {joysticks[jsindex]["path"]} forward') 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:48,代码来源:joy.py


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