2014/12/07 7M4MON
from evdev import UInput, ecodes as e from serial import Serial from fcntl import ioctl from termios import ( TIOCMIWAIT, TIOCM_CTS ) ser = Serial('/dev/ttyUSB0') wait_signals = (TIOCM_CTS) ui = UInput() if __name__ == '__main__': while True: ioctl(ser.fd, TIOCMIWAIT, wait_signals) if ser.getCTS(): ui.write(e.EV_KEY, e.KEY_A, 1) # KEY_A down ui.syn() else: ui.write(e.EV_KEY, e.KEY_A, 0) # KEY_A up ui.syn() |