本文整理汇总了Python中evdev.UInput.syn方法的典型用法代码示例。如果您正苦于以下问题:Python UInput.syn方法的具体用法?Python UInput.syn怎么用?Python UInput.syn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evdev.UInput
的用法示例。
在下文中一共展示了UInput.syn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_data
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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
示例2: executaAcao
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例3: isConnected
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例4: execute
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例5: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例6: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [as 别名]
class DeviceWriter:
def __init__(self, scale):
self.scale = scale
# most values were taken from running
# InputDevice('/dev/input/event$N').capabilities()
vendor = 1133
product = 0
version = 273
bustype = 3
caps = {
e.EV_KEY: [e.BTN_0, e.BTN_1],
e.EV_REL: [e.REL_X, e.REL_Y, e.REL_Z, e.REL_RX, e.REL_RY, e.REL_RZ],
}
device_name = 'Virtual SpaceNav'
self.state = True
self.ui = UInput(caps, vendor=vendor, product=product,
version=version, bustype=bustype, name=device_name)
def make_event(self, data):
if not self.state:
return
for v in (data.linear, data.angular):
# We don't want to write zeroes because the real spacenav never does,
# instead write a small value inside Earth's gutter to prevent drift.
if v.x == 0:
v.x = 1.0 / self.scale
if v.y == 0:
v.y = 1.0 / self.scale
if v.z == 0:
v.z = 1.0 / self.scale
# write some event to self.ui based off of the twist data
_time = time.time()
stime = int(_time)
utime = int((float(_time) - stime) * 10 ** 6)
x = InputEvent(stime, utime, e.EV_REL, e.REL_X, -self.translate(data.linear.y))
y = InputEvent(stime, utime, e.EV_REL, e.REL_Y, -self.translate(data.linear.x))
z = InputEvent(stime, utime, e.EV_REL, e.REL_Z, -self.translate(data.linear.z))
ax = InputEvent(stime, utime, e.EV_REL, e.REL_RX, -self.translate(data.angular.y))
ay = InputEvent(stime, utime, e.EV_REL, e.REL_RY, -self.translate(data.angular.x))
az = InputEvent(stime, utime, e.EV_REL, e.REL_RZ, -self.translate(data.angular.z))
# write all events
self.ui.write_event(x)
self.ui.write_event(y)
self.ui.write_event(z)
self.ui.write_event(ax)
self.ui.write_event(ay)
self.ui.write_event(az)
# syn to alert input subsystem
self.ui.syn()
def translate(self, n):
return int(n * self.scale) # TODO find the translation...
def set_state(self, msg):
self.state = msg.state == ApplicationState.VISIBLE
示例7: TestListener
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例8: EvdevWriter
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例9: PointerWatcher
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例10: call
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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?"
示例11: writeWord
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [as 别名]
def writeWord(word):
listOfLetters = list(word)
ui = UInput()
for letter in listOfLetters:
if letter.isupper():
letter = letter.lower()
case = 'upper'
else:
case = 'lower'
writeUiCase(letter, ui, case)
ui.syn()
ui.close()
示例12: Player
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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
示例13: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例14: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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()
示例15: polling_loop
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import syn [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)