ROUGE = [255, 0, 0] VERT = [0, 255, 0] FGC = WHITE BGC = BLACK print("Press Ctrl-C to quit") time.sleep(1) x=0; y=0; enter = 0 sense = SenseHat() sense.clear() # Blank the LED matrix sense.low_light = True found = False; devices = [InputDevice(fn) for fn in list_devices()] for dev in devices: if dev.name == 'Raspberry Pi Sense HAT Joystick': found = True; break if not(found): print('Raspberry Pi Sense HAT Joystick not found. Aborting ...') sys.exit() # 0, 0 = Top left # 7, 7 = Bottom right UP_PIXELS = [[3, 0], [4, 0]] DOWN_PIXELS = [[3, 7], [4, 7]] LEFT_PIXELS = [[0, 3], [0, 4]] RIGHT_PIXELS = [[7, 3], [7, 4]]
#import evdev from evdev import InputDevice, categorize, ecodes import serial import math ser = serial.Serial('/dev/ttyUSB0',115200) # open serial port print(ser.name) ser.write(b'start') # write a string ser.close() #creates object 'gamepad' to store the data #you can call it whatever you like gamepad = InputDevice('/dev/input/event0') #button code variables (change to suit your device) aBtn = 304 bBtn = 305 xBtn = 307 yBtn = 308 up = 17 down = 17 left = 16 right = 16 start = 315 select = 314 lTrig = 310 rTrig = 311
from evdev import InputDevice, categorize, ecodes from phue import Bridge import random # general info Makey Makey: https://learn.sparkfun.com/tutorials/makey-makey-quickstart-guide & https://learn.sparkfun.com/tutorials/makey-makey-advanced-guide # evdev library: https://python-evdev.readthedocs.io/en/latest/ # phue library: https://github.com/studioimaginaire/phue if __name__ == '__main__': # this is based on a RaspberryPI your input device will be named different and may live # somewehere else depending on your operating system dev = InputDevice( '/dev/input/by-id/usb-Arduino_LLC_Arduino_Leonardo-if02-event-mouse') lightsOn = False b = Bridge('10.200.200.157') # If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time) b.connect() # Get the bridge state (This returns the full dictionary that you can explore) b.get_api() # loop through the events for event in dev.read_loop(): # check if we have a key event if event.type == ecodes.EV_KEY: # print some debug info print(categorize(event))
def __init__(self, evt_f='/dev/input/event0'): self.input = InputDevice(evt_f) self.ctrls = set() self.on = True
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))
import evdev from evdev import InputDevice import os MOD_FILE = "/dev/input/by-id/usb-C-Media_Electronics_Inc._USB_Audio_Device-event-if03" SH_VOLUME_DEC = """ CUR_VOL=$(amixer get Speaker | grep -E -o '[%[0-9]{1,3}%]' | head -1 | grep -E -o '[0-9]{1,3}') let NEW_VOL=$CUR_VOL-5 amixer set 'Speaker' "$NEW_VOL%" > /dev/zero """ SH_VOLUME_INC = """ CUR_VOL=$(amixer get Speaker | grep -E -o '[%[0-9]{1,3}%]' | head -1 | grep -E -o '[0-9]{1,3}') let NEW_VOL=$CUR_VOL+5 amixer set 'Speaker' "$NEW_VOL%" > /dev/zero """ head_set = InputDevice(MOD_FILE) for evt in head_set.read_loop(): if evt.value == 1: if evt.code == 114: os.system(SH_VOLUME_DEC) pass elif evt.code == 115: os.system(SH_VOLUME_INC) pass print(SH_VOLUME_INC)
def get_devices(): return [InputDevice(fn) for fn in list_devices()]
# import evdev from evdev import InputDevice, categorize, ecodes # creates object 'gamepad' to store the data # you can call it whatever you like gamepad = InputDevice("/dev/input/event15") # prints out device info at start print(gamepad) # evdev takes care of polling the controller in a loop for event in gamepad.read_loop(): # filters by event type print("**------------------------------") if event.type == ecodes.EV_KEY: print(event) else: print(event.value) # Não entendi o porque o código ev_key dos direcionais não
spec = importlib.util.spec_from_file_location("main_config", parsed_args.config_file) main_config = importlib.util.module_from_spec(spec) spec.loader.exec_module(main_config) else: import main_config modeAwesome = main_config.main_mode capup = False powermode = False awesomemode = True key_states = {} special_key = {} print("grabbing and listening device /dev/input/event" + parsed_args.input_id) dev = InputDevice('/dev/input/event' + parsed_args.input_id) ui = UInput() dev.grab() def up_all_keys(): for key, is_kup in key_states.items(): if is_kup: ui.write(e.EV_KEY, e.ecodes[key], 0) ui.syn() # TODO: should be encapsulated by a 'resolver' for event in dev.read_loop(): if event.type == e.EV_KEY: if parsed_args.debug: print("event keycode",categorize(event).keycode) kevent = categorize(event)
from evdev import InputDevice, categorize, ecodes controller = InputDevice('/dev/input/event0') print(controller) def readInput(): events = controller.read() try: for event in events: print(event) except IOError: pass #return state while (True): readInput()
def Controller(pub, v, rate): global autonomous gamepad = InputDevice('/dev/input/event17') for event in gamepad.read_loop(): if event.code == 04: if event.value == 589834: autonomous = True break elif event.value == 589833: autonomous = False v.leftwheel=v.rightwheel=0; break elif event.code == 17: if event.value == -1: v.leftwheel=v.rightwheel=24 # Forward v.Check = 0 print (v) break if event.value == 1: v.leftwheel=v.rightwheel=-24 v.Check = 0 # Backward print (v) break elif event.code == 16: if event.value == -1: v.leftwheel=-24 v.rightwheel=24 #left v.Check = 0 print (v) break if event.value == 1: v.leftwheel=24 v.rightwheel=-24 #right v.Check = 0 print (v) break elif event.value == 0: v.leftwheel = v.rightwheel = 0 v.Check = 0 print (v) break else: v.leftwheel=v.rightwheel = 0 v.Check=0 print(v) break pub.publish(v) rate.sleep()
def event_path(i): return '/dev/input/event' + str(i) ## Call Testing Functions test_forward() test_backward() test_right() test_left() ## Setup GamePad #gamepad = InputDevice('/dev/input/event1') i = 0 while exists(event_path(i)): gamepad = InputDevice(event_path(i)) if gamepad.name == "Logitech Gamepad F310": break i += 1 else: print("ERROR: Game pad cannot be found!") quit() button_commands = { 304: bck, # btn_a 305: rgt, # btn_b 308: fwd, # btn_y 307: lft, # btn_x #17 : fwd, # pad_up #17 : bck, # pad_down #16 : rgt, # pad_right
from threading import Timer, Thread from time import sleep from evdev import InputDevice, categorize, ecodes import pygame FPS = 60 pygame.init() pygame.mixer.quit() clock = pygame.time.Clock() if os.path.islink('/dev/input/by-id/usb-JoyLabz_Makey_Makey_v1.20aa_60000000-event-kbd'): dev = InputDevice('/dev/input/by-id/usb-JoyLabz_Makey_Makey_v1.20aa_60000000-event-kbd') elif os.path.islink('/dev/input/by-id/usb-JoyLabz_Makey_Makey_v1.20aa_60000000-if01-event-mouse'): dev = InputDevice('/dev/input/by-id/usb-JoyLabz_Makey_Makey_v1.20aa_60000000-if01-event-mouse') else: print "No MakeyMakey/Arduino Leonardo found:-(" sys.exit(1) inoteMap = { ecodes.KEY_RIGHT: 'R1', ecodes.KEY_LEFT: 'R2', ecodes.KEY_UP: 'R3', ecodes.KEY_DOWN: 'R4', ecodes.KEY_SPACE: 'GO' }
# Code and setup from https://core-electronics.com.au/tutorials/using-usb-and-bluetooth-controllers-with-python.html #import evdev from evdev import InputDevice, categorize, ecodes #creates object 'gamepad' to store the data #you can call it whatever you like media_buttons = InputDevice('/dev/input/event1') #prints out device info at start print(media_buttons) #evdev takes care of polling the controller in a loop for event in media_buttons.read_loop(): # print(categorize(event)) #filters by event type if event.type == ecodes.EV_KEY: print(event)
def get_devices_from_paths(device_paths): return [InputDevice(device_fn) for device_fn in device_paths]
# if ref_pixel[2] > 160 and ref_pixel[0] <30 and ref_pixel[1] <30: # convert_img[i][j] = DEBUG # imsave(OUTPUT_PATH + '%06d' % frame + '_seg.png', convert_img) return convert_img # ============================================================================== # -- main() -------------------------------------------------------------------- # ============================================================================== if __name__ == '__main__': import time # force feedback import evdev from evdev import ecodes, InputDevice device = evdev.list_devices()[0] evtdev = InputDevice(device) val = 25000 #[0,65535] evtdev.write(ecodes.EV_FF, ecodes.FF_AUTOCENTER, val) argparser = argparse.ArgumentParser( description='CARLA Manual Control Client') argparser.add_argument( '-v', '--verbose', action='store_true', dest='debug', help='print debug information') argparser.add_argument( '--host', metavar='H', default='127.0.0.1', help='IP of the host server (default: 127.0.0.1)')
def listen_rfid(self): global pin global accessLogId keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" dev = InputDevice('/dev/input/event0') rfid_presented = "" while True: r,w,x = select([dev], [], []) for event in dev.read(): if event.type==1 and event.value==1: if event.code==28: dbConnection = MySQLdb.connect(host=dbHost, user=dbUser, passwd=dbPass, db=dbName) cur = dbConnection.cursor(MySQLdb.cursors.DictCursor) cur.execute("SELECT * FROM access_list WHERE rfid_code = '%s'" % (rfid_presented)) if cur.rowcount != 1: self.welcomeLabel.config(text="ACCESS DENIED") # Log access attempt cur.execute("INSERT INTO access_log SET rfid_presented = '%s', rfid_presented_datetime = NOW(), rfid_granted = 0" % (rfid_presented)) dbConnection.commit() time.sleep(3) self.welcomeLabel.grid_forget self.show_idle() else: user_info = cur.fetchone() userPin = user_info['pin'] self.welcomeLabel.grid_forget() self.validUser = ttk.Label(self.tk, text="Welcome\n %s" % (user_info['name']), font='size, 15', justify='center', anchor='center') self.validUser.grid(columnspan=3, sticky=tk.W+tk.E) self.image = tk.PhotoImage(file=user_info['image'] + ".gif") self.photoLabel = ttk.Label(self.tk, image=self.image) self.photoLabel.grid(columnspan=3) self.enterPINlabel = ttk.Label(self.tk, text="Please enter your PIN:", font='size, 18', justify='center', anchor='center') self.enterPINlabel.grid(columnspan=3, sticky=tk.W+tk.E) pin = '' keypad = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#', ] # create and position all buttons with a for-loop # r, c used for row, column grid values r = 4 c = 0 n = 0 # list(range()) needed for Python3 self.btn = list(range(len(keypad))) for label in keypad: # partial takes care of function and argument #cmd = partial(click, label) # create the button self.btn[n] = tk.Button(self.tk, text=label, font='size, 18', width=4, height=1, command=lambda digitPressed=label:self.codeInput(digitPressed, userPin)) # position the button self.btn[n].grid(row=r, column=c, ipadx=10, ipady=10) # increment button index n += 1 # update row/column position c += 1 if c > 2: c = 0 r += 1 # Log access attempt cur.execute("INSERT INTO access_log SET rfid_presented = '%s', rfid_presented_datetime = NOW(), rfid_granted = 1" % (rfid_presented)) dbConnection.commit() accessLogId = cur.lastrowid self.PINentrytimeout = threading.Timer(10, self.returnToIdle_fromPINentry) self.PINentrytimeout.start() self.PINenteredtimeout = threading.Timer(5, self.returnToIdle_fromPINentered) rfid_presented = "" dbConnection.close() else: rfid_presented += keys[ event.code ]
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests from evdev import InputDevice from select import select from conf import * params = {} webmoteurl = '' dev = InputDevice(mouse) while True: (r, w, x) = select([dev], [], []) for event in dev.read(): print event.value # scroll wheel event is 8 # buttons left 272, right 273 if event.code == 8: print 'wheel' print event.value if event.value == -1: print 'vol down' params = {'command': 'volume-down'} webmoteurl = 'http://localhost/command' myheaders = {'User-Agent': 'Mozilla/5.0'} r = requests.post(webmoteurl, data=params, headers=myheaders) print r.status_code
def __init__(self, config, inputdevice): self.config = config self.input_device = InputDevice(inputdevice)
from evdev import InputDevice, categorize, ecodes gamepad = InputDevice('/dev/input/eventX') #replace w/ actual address #replace w/ actual ecodes lTrig = 0 rTrig = 0 up = 0 down = 0 left = 0 right = 0 def testController(gamepad): print(gamepad) for event in gamepad.read_loop(): print(categorize(event)) def findEcodes(gamepad): print(gamepad) for event in gamepad.read_loop(): if event.type == ecodes.___: #replace w/ event code (ecode) type print(categorize(event)) def testEcodes(gamepad): for event in gamepad.read_loop(): if event.type == ecodes.___: #gotta find this
from evdev import InputDevice, categorize, ecodes, KeyEvent, util devices = [InputDevice(fn) for fn in util.list_devices()] for device in devices: if device.name == 'Logitech Gamepad F710' or device.name == 'Logitech Gamepad F310': gamePad = InputDevice(device.fn) break print("\nPrint gamepad object information\n") print(gamePad) print("\n") print("Press gamepad buttons\n") for event in gamePad.read_loop(): if event.type == ecodes.EV_KEY: keyevent = categorize(event) print(keyevent) print("") if keyevent.keystate == KeyEvent.key_down: print('key down detected') print("keyevent.keycode") print(keyevent.keycode) print("") if keyevent.keycode[1] == 'BTN_X': print('button X\n') elif keyevent.keycode[0] == 'BTN_B':
import threading from evdev import InputDevice, ecodes import control as control import constants as CONST # thread infrared_thread = None dev = InputDevice("/dev/input/event0") dev.grab() def _infrared_loop(): t = threading.current_thread() for event in dev.read_loop(): if event.type == ecodes.EV_KEY: if t.name == "stop": break if event.code == 78 and event.value: control.control_up(CONST.VOLUME_CHANGE_DIFF) elif event.code == 74 and event.value: control.control_down(-CONST.VOLUME_CHANGE_DIFF) elif event.code == 208 and event.value: control.control_next() elif event.code == 168 and event.value: control.control_prev() elif event.code == 207 and event.value: control.control_pause_toggle() elif event.code == 139 and event.value: control.control_mute_toggle()
devlist = devfd.readlines() devlist2 = "".join(devlist).split("\n\n") for dev in devlist2: if "Sysfs" in dev and "keyboard" in dev.lower(): for line in filter(lambda str: str.startswith("H: Handlers="), dev.split("\n")): for unit in line.split(" "): if unit.startswith("event"): devname = "/dev/input/" + unit if not devname: exit(1) time.sleep(1) dev = InputDevice(devname) pressTime = None releaseTime = None longPressTime = None """ run loop. """ while True: r, w, x = select([dev], [], []) for event in dev.read(): if (event.type == 1): # vaild key event print(event.code) if event.code in Keys.keyDic.values(): # The Key Value 1 Is Means Press
def main(): ReStart() # creates object gamepad gamepad = InputDevice('/dev/input/event1') # prints out device info at start print(gamepad) # define codes of the remote controllers # Ground Movement global lastcomm lastcomm = 0 global climbmode climbmode = 0 frwdBtn = 544 bkwdBtn = 545 lftBtn = 546 rgtBtn = 547 lBtn = 292 rBtn = 293 selBtn = 314 startBtn = 315 oBtn = 305 squareBtn = 308 triangleBtn = 307 xBtn = 304 L1btn = 310 R1btn = 311 # display codes for event in gamepad.read_loop(): #Boutons | buttons if event.type == ecodes.EV_KEY: #print(event) if event.value == 1: if event.code == frwdBtn: if climbmode == 0: print("Forward") moveforward() elif climbmode == 1: print("Climb Upward") climbUpward() continue elif event.code == bkwdBtn: if climbmode == 0: print("Backward") movebackward() elif climbmode == 1: print("Climb Downward") climbDownward() continue elif event.code == lftBtn: if climbmode == 0: print("move left") turnleft() elif climbmode == 1: print("climb Up Stroke") climbUpStroke() continue elif event.code == rgtBtn: if climbmode == 0: print("move right") turnright() elif climbmode == 1: print("climb Down Stroke") climbDownStroke() continue elif event.code == triangleBtn: if climbmode == 0: ### need something here print("front leg forward") frontlegforward() elif climbmode == 1: print("Front Leg Climb Up") frontlegclimbup() continue elif event.code == squareBtn: if climbmode == 0: ### need something here print("front leg backward") frontlegbackward() elif climbmode == 1: print("front leg climb down") frontlegclimbdown() continue elif event.code == oBtn: if climbmode == 0: ### need something here print("rear leg forward") rearlegforward() elif climbmode == 1: print("Rear Leg Climb Up") rearlegclimbup() continue elif event.code == xBtn: if climbmode == 0: ### need something here print("rear leg backward") rearlegbackward() elif climbmode == 1: print("rear leg climb down") rearlegclimbdown() continue elif event.code == L1btn: if kit.servo[1].angle >= 0 and kit.servo[ 1].angle <= 170 and kit.servo[ 3].angle >= 10 and kit.servo[3].angle <= 180: print("1:" + str(kit.servo[1].angle + 10)) kit.servo[1].angle = kit.servo[1].angle + 10 print("3:" + str(kit.servo[3].angle - 10)) kit.servo[3].angle = kit.servo[3].angle - 10 pass elif event.code == R1btn: if kit.servo[7].angle >= 0 and kit.servo[ 7].angle <= 170 and kit.servo[ 5].angle >= 10 and kit.servo[5].angle <= 180: kit.servo[5].angle = kit.servo[5].angle - 10 kit.servo[7].angle = kit.servo[7].angle + 10 pass elif event.code == selBtn: print("Select") climbMode() elif event.code == startBtn: print("ReStart") ReStart() elif event.value == 0: print("Release") # Analog gamepad elif event.type == ecodes.EV_ABS: absevent = categorize(event) #print ecodes.bytype[absevent.event.type][absevent.event.code], absevent.event.value if ecodes.bytype[absevent.event.type][ absevent.event.code] == "ABS_Z": #L2 print("L1btn: Release the Front Grip") kit.servo[1].angle = 30 kit.servo[3].angle = 150 elif ecodes.bytype[absevent.event.type][ absevent.event.code] == "ABS_RZ": #R2 print("R1btn: Release the Rear Grip") kit.servo[5].angle = 150 kit.servo[7].angle = 30 # Incremental Spine Movement elif ecodes.bytype[absevent.event.type][ absevent.event.code] == "ABS_X": if absevent.event.value < 127: tempangle = kit.servo[8].angle + 5 if tempangle >= 0 and tempangle <= 180: kit.servo[8].angle = tempangle elif absevent.event.value > 127: tempangle = kit.servo[8].angle - 5 if tempangle >= 0 and tempangle <= 180: kit.servo[8].angle = tempangle elif absevent.event.value == 127: print("Hold position") pass elif ecodes.bytype[absevent.event.type][ absevent.event.code] == "ABS_Y": if absevent.event.value < 127: tempangle = kit.servo[10].angle - 5 if tempangle >= 0 and tempangle <= 180: kit.servo[10].angle = tempangle elif absevent.event.value > 127: tempangle = kit.servo[10].angle + 5 if tempangle >= 0 and tempangle <= 180: kit.servo[10].angle = tempangle elif absevent.event.value == 127: print("Hold position") pass elif ecodes.bytype[absevent.event.type][ absevent.event.code] == "ABS_RX": if absevent.event.value < 127: tempangle = kit.servo[9].angle - 5 if tempangle >= 0 and tempangle <= 180: kit.servo[9].angle = tempangle elif absevent.event.value > 127: tempangle = kit.servo[9].angle + 5 if tempangle >= 0 and tempangle <= 180: kit.servo[9].angle = tempangle elif absevent.event.value == 127: print("Hold position") pass pass
def list_devices(): devices = [InputDevice(fn) for fn in evdev.list_devices()] for device in reversed(devices): yield [device.fn, device.phys, device.name]
from evdev import InputDevice, categorize, ecodes #creates object 'gamepad' to store the data #you can call it whatever you like gamepad0 = InputDevice('/dev/input/event4') gamepad1 = InputDevice('/dev/input/event5') gamepad2 = InputDevice('/dev/input/event6') gamepad3 = InputDevice('/dev/input/event7') gamepad4 = InputDevice('/dev/input/event8') #prints out device info at start print(gamepad0) print(gamepad1) print(gamepad2) print(gamepad3) print(gamepad4) #evdev takes care of polling the controller in a loop for event in gamepad4.read_loop(): print(event.code, event.value)
import evdev from evdev import categorize from evdev import UInput from evdev import InputDevice from evdev import ecodes as e UDP_IP = '0.0.0.0' UDP_PORT = 8444 DEVICES = [evdev.InputDevice(fn) for fn in evdev.list_devices()] PS4 = None for dev in DEVICES: if dev.name == 'Sony Computer Entertainment Wireless Controller': PS4 = dev.fn INPUT_DEVICE = InputDevice(PS4) USER_INPUT = UInput.from_device(INPUT_DEVICE, name='xboxdrv_emu') print('Found PS4-controller.') SOCK = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) SOCK.bind((UDP_IP, UDP_PORT)) while True: data, addr = SOCK.recvfrom(10000000) LIST = [re.sub('[^A-Za-z0-9.-]+', "", x) for x in data.split(",")] CONTROLLER_1 = LIST[0:15] CONTROLLER_2 = LIST[15:30] # Lateral movement, min: 0, max: 255 [int]
] ### ### GAMEPAD CONFIG gamepads = [] def devicenum(device_path): digits = re.findall(r'\d+$', device_path) return [int(i) for i in digits] if gamepadsAvailable: devices = sorted(list_devices('/dev/input'), key=devicenum) devices = devices = [InputDevice(path) for path in devices] for device in devices: if 'Shinecon' in device.name: gamepads += [device] def getGamepad(name): for gamepad in gamepads: if name in gamepad.name: return gamepad return None ### ### PLAYER CONFIG
def get_devices_list(): return [InputDevice(device_fn) for device_fn in reversed(list_devices())]
#! /usr/bin/python from evdev import UInput, InputDevice, categorize, ecodes dev = InputDevice( '/dev/input/by-id/usb-NOVATEK_Kensington_U+P_Keyboard-event-kbd') dev.grab() for event in dev.read_loop(): if event.type == ecodes.EV_KEY: key = categorize(event) if key.keystate == key.key_down: if key.keycode == 'KEY_ESC': quit() else: print(key)