Skip to content

Instantly share code, notes, and snippets.

@hristo-vrigazov
Created September 12, 2016 14:58
Show Gist options
  • Save hristo-vrigazov/d50129268777f8d361cc92e88aa1b509 to your computer and use it in GitHub Desktop.
Save hristo-vrigazov/d50129268777f8d361cc92e88aa1b509 to your computer and use it in GitHub Desktop.
import asyncio, evdev
from mouse_handlers import left_mouse_down, left_mouse_up
from mouse_handlers import right_mouse_down, right_mouse_up
from evdev import ecodes
mouse_file = '/dev/input/event6'
keyboard_file = '/dev/input/event9'
down = 1
up = 0
@asyncio.coroutine
def print_events(device):
while True:
events = yield from device.async_read()
for event in events:
if device.fn == mouse_file:
if event.type == ecodes.EV_REL:
print('Relative')
elif event.type == ecodes.EV_KEY:
print(event.code)
print(ecodes.BTN_LEFT)
if event.code == ecodes.BTN_LEFT:
if event.value == down:
left_mouse_down()
print('Left mouse down')
elif event.value == up:
left_mouse_up()
print('Left mouse up')
else:
print('Left mouse unknown event')
elif event.code == ecodes.BTN_RIGHT:
if event.value == down:
right_mouse_down()
print('Right mouse down')
elif event.value == up:
right_mouse_up()
print('Right mouse up')
else:
print('Right mouse unknown event')
else:
print('Global unknown event')
elif device.fn == keyboard_file:
if event.code is ecodes.KEY_A:
print("Key A")
if event.value is down:
print('Key down')
elif event.value is up and event.type is 1:
print('Key up')
else:
pass
else:
print('Other event')
# print(device.fn, evdev.categorize(event), sep=': ')
mouse = evdev.InputDevice(mouse_file)
keyboard = evdev.InputDevice(keyboard_file)
for device in mouse, keyboard:
asyncio.ensure_future(print_events(device))
loop = asyncio.get_event_loop()
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment