当前位置: 首页>>代码示例>>Python>>正文


Python UInput.write方法代码示例

本文整理汇总了Python中evdev.UInput.write方法的典型用法代码示例。如果您正苦于以下问题:Python UInput.write方法的具体用法?Python UInput.write怎么用?Python UInput.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在evdev.UInput的用法示例。


在下文中一共展示了UInput.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: executaAcao

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
def executaAcao(tecla):
        ui = UInput()
        print tecla
        ui.write(e.EV_KEY, e.ecodes[tecla], 1) #key down
        ui.write(e.EV_KEY, e.ecodes[tecla], 0) #key up
        ui.syn()
        ui.close()
开发者ID:joaoluizdhv,项目名称:controlearduino,代码行数:9,代码来源:controle.py

示例2: read_data

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
def read_data(ep_in):
    """
    Read the transmitted android keycodes from the input endpoint and trigger the corresponding key presses in linux.
    :param ep_in: input endpoint of the accessory device.
    """
    ui = UInput()
    while True:
        try:
            data = ep_in.read(3)
            keycode = data[1] * 0xFF + data[2]
            evdev_keycode = get_evdev_keycode(keycode)
            if data[0] == 0:
                print("Key down {}".format(keycode))
                if evdev_keycode != -1:
                    ui.write(ecodes.EV_KEY, evdev_keycode, 1)
                    ui.syn()
            elif data[0] == 1:
                print("Key up {}".format(keycode))
                if evdev_keycode != -1:
                    ui.write(ecodes.EV_KEY, evdev_keycode, 0)
                    ui.syn()
        except usb.core.USBError as e:
            # ignore exceptions caused by read timeout
            if e.errno == 110:
                pass
            else:
                print("failed to read input")
                print(e)
                break
开发者ID:WIStudent,项目名称:Android-Raspberry-Pi-Keyboard,代码行数:31,代码来源:accessory.py

示例3: execute

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
    def execute(self):
        print "Executing " + e.KEY[self.macroKey] + " macro."
        ui = UInput()

        for i in range(len(self.keySequence)):
            ui.write(e.EV_KEY, self.keySequence[i], self.keyState[i]);
        ui.syn()
        ui.close()
开发者ID:wassonan,项目名称:macro,代码行数:10,代码来源:macro.py

示例4: __init__

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class Input:
    def __init__(self):
        self._ui = UInput()

    def inject_event(self, keycode, typ):
	print "Injecting keycode: %s\n" % keycode
        self._ui.write(ecodes.EV_KEY, keycode, typ)
        self._ui.syn()
开发者ID:festlv,项目名称:carpc,代码行数:10,代码来源:serial_uinput.py

示例5: isConnected

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class KeyboardOutputDevice:

    device = None

    def isConnected(self):
        return self.device is not None

    def __init__(self, deviceName='LilyFrog'):

        print 'Open keyboard output device.'
        self.device = UInput(name=deviceName)

    def stop(self):

        if self.isConnected():
            print 'Close keyboard output device.'
            self.device.close()
            self.device = None
            
    def pressKeyString(self, keystr):
        
        # print 'pressKeyString => %s' % keystr

        if not len(keystr): return

        scancodes = []

        for keychr in keystr:

            if keychr in KeyChrToCodeMap:

                scancode = KeyChrToCodeMap[keychr]
                scancodes.extend(scancode)

            else: raise ValueError('Invalid key string value \'%s\'!' % keychr)

        self.pressKeys(scancodes)

    def pressKeys(self, scancodes):

        if not len(scancodes): return

        for scancode in scancodes:

            isShiftRequired = isinstance(scancode, list)

            if not isShiftRequired:

                self.device.write(EV_KEY, scancode, KeyEvent.key_down)
                self.device.write(EV_KEY, scancode, KeyEvent.key_up)

            else:

                self.device.write(EV_KEY, KEY_LEFTSHIFT, KeyEvent.key_down)
                self.device.write(EV_KEY, scancode[0],   KeyEvent.key_down)
                self.device.write(EV_KEY, scancode[0],   KeyEvent.key_up)
                self.device.write(EV_KEY, KEY_LEFTSHIFT, KeyEvent.key_up)

        self.device.syn()
开发者ID:jurihock,项目名称:lilyfrog,代码行数:61,代码来源:KeyboardOutputDevice.py

示例6: call

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
def call(k, conf=False):
    if conf:
        keys = defns._k[k]
    else:
        keys = defns.default[k]
    try:
        ui = UInput()
        for key in keys:
            ui.write(defns.k["EV_KEY"], defns.k["KEY_" + key.upper()], 1)
        defns._k[k].reverse()
        for key in keys:
            ui.write(defns.k["EV_KEY"], defns.k["KEY_" + key.upper()], 0)
        ui.syn()
        ui.close()
    except err:
        print "Not enough permissions. Are you root?"
开发者ID:Sthasudip,项目名称:squRemote-py,代码行数:18,代码来源:sim.py

示例7: Player

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class Player(Thread):
    def __init__(self, n, m):
        Thread.__init__(self)
        self.n = n
        self.stop = False
        self.sleep = False
        self.ui = UInput()
        self.m = m
    
    def sendEvent(self):
        i = 0
        while i < len(history):
            now = history[i]
            if i < len(history)-1: after = history[i+1]
                
            if self.stop: break
            if not self.sleep:
                m.move( now.get("mouse")[0], now.get("mouse")[1])
                if now.get("event").type == ecodes.EV_KEY:
                    self.ui.write(ecodes.EV_KEY, now.get("event").code, now.get("event").value)
                    self.ui.syn()
                if i < len(history):
                    time.sleep(float(after.get("event").sec - now.get("event").sec)+float(after.get("event").usec - now.get("event").usec)/1000000)
                i += 1
    
    # sobrescrevendo o metodo run()
    def run(self):
        if self.n == 0:
            while not self.stop:
                self.sendEvent()
        elif self.n > 0:
            for i in range(self.n):
                self.sendEvent()
        self.stop = True
        print "\rEnd               "
        ui.close()
    
    def Stop(self):
        self.stop = True
    
    def Sleep(self):
        self.sleep = not self.sleep
开发者ID:andredalton,项目名称:bcc,代码行数:44,代码来源:kmlogger.py

示例8: __init__

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class Keyboard:

    def __init__(self):
        self.ui = UInput()

    def press_key(self, list_ecodes):
        """
        Write events to keyboard based on a list of ecodes
        :param list_ecodes
        """

        # key down event (press)
        for code in list_ecodes:
            self.ui.write(ecodes.EV_KEY, code, 1)

        # key up event (release)
        for code in list_ecodes:
            self.ui.write(ecodes.EV_KEY, code, 0)

        # after all keys are writen sync
        self.ui.syn()
开发者ID:ivopanjos,项目名称:TouchpadPro-Python,代码行数:23,代码来源:Keyboard.py

示例9: EvdevWriter

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class EvdevWriter(Writer):

    def __init__(self):
        self.event_to_ecode_translator = EventToEcodeTranslator()
        self.ui = UInput()

    def write_iterable(self, events_iterable):
        for event in events_iterable:
            if isinstance(event, list):
                self.write_combo(event)
            else:
                self.__buffer_event(event)
        self.ui.syn()

    def write_event(self, event):
        self.__buffer_event(event)
        self.ui.syn()

    def __buffer_event(self, event):
        ecode = self.event_to_ecode_translator.translate(event)
        self.ui.write(ecodes.EV_KEY, ecode, 1)
        self.ui.write(ecodes.EV_KEY, ecode, 0)

    def write_combo(self, events):
        for event in events:
            ecode = self.event_to_ecode_translator.translate(event)
            self.ui.write(ecodes.EV_KEY, ecode, 1)
            self.ui.syn()
        for event in reversed(events):
            ecode = self.event_to_ecode_translator.translate(event)
            self.ui.write(ecodes.EV_KEY, ecode, 0)
            self.ui.syn()

    def close(self):
        self.ui.close()
开发者ID:GMadorell,项目名称:panoptes,代码行数:37,代码来源:evdev_writer.py

示例10: PointerWatcher

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class PointerWatcher(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.ui = UInput()
        self.devices = []
        self.running = True
        self.device_search()

    def device_search(self):
        devices_list = []
        files = []
        for (dirpath, dirnames, filenames) in walk(INPUTDIR):
            files.extend(filenames)
            break
        for f in files:
            try:
                dev = InputDevice(path.join(INPUTDIR, f))
                if dev.name == "W WirelessUSB":
                    devices_list.append(dev)
            except (IOError, OSError, TypeError):
                pass
        self.devices = {dev.fd: dev for dev in devices_list}

    def run(self):
        c = 0
        if len(self.devices) > 0:
            while self.running:
                r, w, x = select(self.devices, [], [])
                for fd in r:
                    try:
                        for event in self.devices[fd].read():
                            if event.code == ecodes.KEY_UP and event.value == 1:
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_DOWN, 1)
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_DOWN, 0)
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_LEFT, 1)
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_LEFT, 0)
                                self.ui.syn()
                                c += 1
                            elif event.code == ecodes.KEY_DOWN and event.value == 1:
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_UP, 1)
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_UP, 0)
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_RIGHT, 1)
                                self.ui.write(ecodes.EV_KEY, ecodes.KEY_RIGHT, 0)
                                self.ui.syn()
                                c -= 1
                    except IOError:
                        self.running = False
                        break
        self.ui.close()
开发者ID:andredalton,项目名称:kmlogger,代码行数:51,代码来源:pointer.py

示例11: __init__

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class KeyHandler:

    def __init__(self, mod_mapping, key_mapping):
        self._ui = UInput()
        self._mod_mapping = mod_mapping
        self._key_mapping = key_mapping

    def chord_event(self, mods, virtual_mods, chord, value):
        chord_keys = self.map_chord(virtual_mods, chord)
        if value == 0:
            chord_keys = chord_keys + self.map_mods(mods)
        else:
            chord_keys = self.map_mods(mods) + chord_keys

        for key in chord_keys:
            self._ui.write(EV_KEY, key, value)
        self._ui.syn()

    def map_chord(self, virtual_mods, chord):
        frozen_vmods = frozenset(virtual_mods)
        if frozen_vmods not in self._key_mapping:
            return []
        current_mapping = self._key_mapping[frozen_vmods]
        frozen_chord = frozenset(chord)
        if frozen_chord not in current_mapping:
            return []
        return current_mapping[frozen_chord]

    def map_mods(self, keys):
        mods = []
        for key in keys:
            mods.append(self._mod_mapping[key])
        return mods

    def close(self):
        self._ui.close()
开发者ID:gehel,项目名称:pykey,代码行数:38,代码来源:KeyHandler.py

示例12: polling_loop

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
def polling_loop(mapping, combinations):
	init_gpio()
	uinput = UInput()

	pin_state = [1]*len(PINS)
	combination_state = [False]*len(combinations)

	while True:
		#start = time()

		# update pin states and trigger single pin events
		for pin in PINS:
			prev = pin_state[pin] # previous pin state
			curr = GPIO.input(pin) # current pin state

			# detect edges
			if prev and not curr and pin in mapping: # falling edge
				uinput.write(ecodes.EV_KEY, mapping[pin], 1)  # key down
				uinput.syn()
			elif not prev and curr and pin in mapping: # rising edge
				uinput.write(ecodes.EV_KEY, mapping[pin], 0)  # key up
				uinput.syn()

			# update pin state
			pin_state[pin] = curr

		# query pin combinations
		for i, (pins, key) in enumerate(combinations):
			hit = True
			for pin in pins:
				if pin_state[pin] == 1:
					hit = False
					break
			if hit and not combination_state[i]:
				combination_state[i] = True
				uinput.write(ecodes.EV_KEY, key, 1)  # key down
				uinput.syn()
			elif not hit and combination_state[i]:
				combination_state[i] = False
				uinput.write(ecodes.EV_KEY, key, 0)  # key up
				uinput.syn()

		#print time() - start

		# wait for next polling cycle
		sleep(POLLING_INTERVAL)
开发者ID:robbeofficial,项目名称:gpio-evdev-driver,代码行数:48,代码来源:gpio-evdev-driver.py

示例13: TestListener

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class TestListener(Leap.Listener):
    hand_id = 0
    spread_win = False
    curtime = 0
    ui = None
    
    def on_init(self, controller):
        self.ui = UInput()
        print "Initialized"

    def on_connect(self, controller):
        print "Connected"

    def on_disconnect(self, controller):
        print "Disconnected"

    def on_exit(self, controller):
        print "Exited"

    def on_frame(self, controller):
        frame = controller.frame() 

        if not frame.hands.is_empty:
            hand = frame.hands[0]

            fingers = hand.fingers
            if not fingers.is_empty:
                if hand.id == self.hand_id and not self.spread_win and len(fingers) >= 4 and (frame.timestamp - self.curtime) <= 1000000:
                    #print "(Spread) Old timestamp is %d, current is %d (%d)" % (self.curtime, frame.timestamp, (frame.timestamp - self.curtime))
                    self.spread_windows()
                    #print "Spread windows"
                    self.spread_win = True
                    self.curtime = frame.timestamp
                    #print "Hand open timestamp is %d" % self.curtime
            else:
                if hand.id == self.hand_id and self.spread_win and (frame.timestamp - self.curtime) <= 1000000:
                    #print "(Unspread) Old timestamp is %d, current is %d (%d)" % (self.curtime, frame.timestamp, (frame.timestamp - self.curtime))
                    self.spread_windows()
                    #print "Unspread windows"
                    self.spread_win = False
                else:
                    self.hand_id = hand.id
                    self.curtime = frame.timestamp
                    #print "Fist timestamp is %d" % self.curtime

    def spread_windows(self):
        self.ui.write(e.EV_KEY, e.KEY_LEFTMETA, 1) # <super> key down
        self.ui.write(e.EV_KEY, e.KEY_W, 1) # 'W' key down
        self.ui.write(e.EV_KEY, e.KEY_W, 0) # 'W' key up
        self.ui.write(e.EV_KEY, e.KEY_LEFTMETA, 0) # <super> key up
        self.ui.syn()
开发者ID:samaritano,项目名称:LeapWM,代码行数:53,代码来源:spread_windows.py

示例14: readData

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
	

if __name__ == '__main__':

	readerIP = "192.168.240.131"
	readerPort = 100

	rfid_data = readData(readerIP, readerPort)
	print(rfid_data)

	books = rfid_data['books']
	patron = rfid_data['patron']
	ui = UInput()

	#Alt-tabing, for testing purpose only
	ui.write(e.EV_KEY, e.ecodes['KEY_LEFTALT'], 1)  # KEY down
	ui.write(e.EV_KEY, e.ecodes['KEY_TAB'], 1)  # KEY down
	ui.write(e.EV_KEY, e.ecodes['KEY_TAB'], 0)  # KEY up
	ui.write(e.EV_KEY, e.ecodes['KEY_LEFTALT'], 0)  # KEY up

	ui.syn()
	sleep(.5)

	#sending patronid 
	keyboard_events = [e.ecodes['KEY_' + i.upper()] for i in patron]

	for key in keyboard_events:
		ui.write(e.EV_KEY, key, 1)  # KEY down
		ui.write(e.EV_KEY, key, 0)  # KEY up
	
	ui.write(e.EV_KEY, e.ecodes['KEY_ENTER'], 1)  # KEY down
开发者ID:daltonfury42,项目名称:desktopDaemon,代码行数:33,代码来源:desktopDaemon.py

示例15: Chatpad

# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write [as 别名]
class Chatpad():
    
    #Some hard-coded things about the ChatPad protocol
    kInitMessage = bytearray([ 0x87, 0x02, 0x8C, 0x1F, 0xCC ])
    kAwakeMessage = bytearray([ 0x87, 0x02, 0x8C, 0x1B, 0xD0 ])
    kShiftMask = (1 << 0)
    kGreenSquareMask = (1 << 1)
    kOrangeCircleMask = (1 << 2)
    kPeopleMask = (1 << 3)
    #Modifier dictionary
    mod_dict = {kShiftMask:1, kGreenSquareMask: 2, kOrangeCircleMask: 3, kPeopleMask: 4}
    #Key dictionary
    key_dict = {17: 'KEY_7', 18: 'KEY_6', 19: 'KEY_5', 20: 'KEY_4', 21: 'KEY_3', 22: 'KEY_2', 23: 'KEY_1', 33: 'KEY_U', 34: 'KEY_Y', 35: 'KEY_T', 36: 'KEY_R', 37: 'KEY_E', 38: 'KEY_W', 39: 'KEY_Q', 49: 'KEY_J', 50: 'KEY_H', 51: 'KEY_G', 52: 'KEY_F', 53: 'KEY_D', 54: 'KEY_S', 55: 'KEY_A', 65: 'KEY_N', 66: 'KEY_B', 67: 'KEY_V', 68: 'KEY_C', 69: 'KEY_X', 70: 'KEY_Z', 81: 'KEY_RIGHT', 82: 'KEY_M', 83: 'KEY_DOT', 84: 'KEY_SPACE', 85: 'KEY_LEFT', 98: 'KEY_COMMA', 99: 'KEY_ENTER', 100: 'KEY_P', 101: 'KEY_0', 102: 'KEY_9', 103: 'KEY_8', 113: 'KEY_BACKSPACE', 114: 'KEY_L', 117: 'KEY_O', 118: 'KEY_I', 119: 'KEY_K'}
    key_dict.update({1: 'KEY_LEFTSHIFT', 2: 'KEY_LEFTCTRL', 3: 'KEY_RIGHTALT', 4:'KEY_LEFTMETA'}) #Adding modifiers in the dictionary - we'll be injecting their keycodes if modifiers will be found

    def __init__(self, port = "/dev/ttyAMA0", name="xbox_chatpad_input", keycode_callback = None, ecode_callback = None):
        self.keycode_callback = keycode_callback
        self.ecode_callback = ecode_callback
        if ecode_callback == None and name: #If we don't have any external callback provided, we should be using a built-in one that uses uinput
            self.ecode_callback = self.uinput_callback
            self.uinput = UInput(name=name, devnode='/dev/uinput')
        if self.keycode_callback == None: #If keycode_callback is not provided
            self.keycode_callback = lambda *args: None #Setting callback to empty function to avoid exceptions 
        if self.ecode_callback == None: #If ecode_callback is not provided
            self.ecode_callback = lambda *args: None #Setting callback to empty function to avoid exceptions 
        self.name = name
        self.port = port
        self.serial = Serial(port, 19200)
        
    def send_init_message(self):
        #print "Init message sent"
        self.serial.write(self.kInitMessage)

    def send_awake_message(self):
        #print "Awake message sent"
        self.serial.write(self.kAwakeMessage)

    def test_chatpad_on_serial(self):
        # TODO: Add Chatpad detection on a serial port (using 5-byte init response messages starting with A5)
        return NotImplementedError

    def uinput_callback(self, pressed, released):
        for key in pressed: 
            #print "Key pressed: "+self.key_dict[key]
            self.uinput.write(ecodes.EV_KEY, ecodes.ecodes[key], 1)
        for key in released:
            #print "Key released: "+self.key_dict[key]
            self.uinput.write(ecodes.EV_KEY, ecodes.ecodes[key], 0)
        self.uinput.syn()

    def listen(self):
        self.send_init_message()
        self.send_awake_message()
        counter = 0
        counter_treshold = 100
        pressed_keys = []
        previous_keys = []
        pressed_modifiers = []
        previous_modifiers = []
        while True:
            while self.serial.inWaiting() > 8:
                #print self.serial.inWaiting()
                data = self.serial.read(1)
                rdata = bytearray(data[0])[0]
                expected = bytearray([0xB4])[0]
                if rdata != expected:
                    #print "Invalid first byte, shuffling further: "+str(rdata)+", expected: "+str(expected)
                    continue
                #print "First byte OK, checking second byte:"
                data += self.serial.read(1)
                rdata = bytearray(data[1])[0]
                expected = bytearray([0xC5])[0]
                if rdata != expected:
                    #print "Invalid second byte, shuffling further: "+str(rdata)+", expected: "+str(expected)
                    continue
                data += self.serial.read(6)
                #Data package received
                #I won't be checking the checksum, too lazy =)
                #print "Data package received: "+str(data)
                pressed_keys = []
                pressed_modifiers = []
                modifiers = bytearray(data[3])[0]
                key0 = bytearray(data[4])[0]
                key1 = bytearray(data[5])[0]
                if key0:
                    #print "Key 0 is: "+str(key0)
                    pressed_keys.append(key0)                   
                if key1: 
                    #print "Key 1 is: "+str(key1)
                    pressed_keys.append(key1)                   
                if not key0 and not key1: 
                    #print "All keys released"
                    pressed_keys = []
                for modifier in self.mod_dict.keys():
                    if modifier & modifiers == modifier:
                        pressed_modifiers.append(self.mod_dict[modifier])
                if previous_keys == pressed_keys and previous_modifiers == pressed_modifiers:
                    continue #Duplicate message received, no need to worry
                #Next lines would be a perfect example of where to use sets - wonder what is their performance and if that would be premature optimisation
                pressed = [key for key in pressed_keys if key not in previous_keys]
#.........这里部分代码省略.........
开发者ID:CRImier,项目名称:ChatpadDriver,代码行数:103,代码来源:driver.py


注:本文中的evdev.UInput.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。