Python evdev.categorize() Examples
The following are 8
code examples of evdev.categorize().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
evdev
, or try the search function
.
Example #1
Source File: input.py From uchroma with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #2
Source File: agent.py From btk with MIT License | 6 votes |
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)
Example #3
Source File: badgereader_hid_keystroking.py From makerspace-auth with Apache License 2.0 | 5 votes |
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
Example #4
Source File: tinyjoy.py From fygimbal with MIT License | 5 votes |
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 = {}
Example #5
Source File: io_evdev_keyboard.py From foos with GNU General Public License v3.0 | 5 votes |
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
Example #6
Source File: evdevremapkeys.py From evdevremapkeys with MIT License | 5 votes |
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)
Example #7
Source File: debug_listener.py From pyLCI with Apache License 2.0 | 5 votes |
def listen_for_events(dev): for event in dev.read_loop(): if event.type == ecodes.EV_KEY: print dev.name+": "+str(categorize(event))
Example #8
Source File: joy.py From aws-builders-fair-projects with Apache License 2.0 | 4 votes |
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')