#logger.debug("sleep 1 second...") time.sleep(7) logger.debug("launching MAIN joystick.py thread") try: thread.start_new_thread(check_process,()) logger.debug("MAIN running! continue with main loop...") except Exception as ex: logger.error(str(ex)) # Main event loop ui = None try: ui = uinput.UInput() except: logger.warning("no uinput was defined") while True: evbuf = jsdev.read(8) #wait until event happens logger.debug("event js: %s" % str(evbuf) ) if evbuf: t, value, type, number = struct.unpack('IhBB', evbuf) if type & 0x80: logger.debug("(initial)") if type & 0x01: button = button_map[number] if button:
import os, sys sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))) import evdev from evdev import uinput, ecodes as e import rospy import imutype.msg as msg import numpy as np import sys # from xdo import Xdo, CURRENTWINDOW, charcodemap_t # xdo = Xdo() rospy.init_node('export_training_data', disable_signals=True) with uinput.UInput() as ui: def onPredictedKeyEvent(event): predicted_key_event = event # charcodemap = (charcodemap_t * 1)(charcodemap_t(code=chr(predicted_key_event.code))) # xdo.send_keysequence_window_list_do(CURRENTWINDOW, charcodemap, pressed=1 if predicted_key_event.pressed else 0) ui.write(e.EV_KEY, predicted_key_event.code, predicted_key_event.pressed) # ui.write(e.EV_KEY, e.KEY_A, 1) ui.syn() rospy.Subscriber('/predicted_key_events', msg.KeyEvent, onPredictedKeyEvent, queue_size=1, tcp_nodelay=True)
def __init__(self): self._uinput = uinput.UInput() self._last_pressed = set()
def test_maxnamelen(c): with raises(uinput.UInputError): c['name'] = 'a' * 150 uinput.UInput(**c)
def test_open_context(c): args = (c['bustype'], c['vendor'], c['product'], c['version']) with uinput.UInput(**c): assert device_exists(*args) assert not device_exists(*args)
def test_open(c): ui = uinput.UInput(**c) args = (c['bustype'], c['vendor'], c['product'], c['version']) assert device_exists(*args) ui.close() assert not device_exists(*args)
def nextt(): with uinput.UInput() as ui: ui.write(e.EV_KEY, e.KEY_SPACE, 1) ui.write(e.EV_KEY, e.KEY_SPACE, 0) ui.syn()
def refresh(self): self.close() for evtype in self.filtered_types: if evtype in self.capabilities: del self.capabilities[evtype] self.uinput_object = uinput.UInput(self.capabilities, **self.kwargs)