本文整理汇总了Python中evdev.UInput.close方法的典型用法代码示例。如果您正苦于以下问题:Python UInput.close方法的具体用法?Python UInput.close怎么用?Python UInput.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evdev.UInput
的用法示例。
在下文中一共展示了UInput.close方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EvdevWriter
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [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()
示例2: executaAcao
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [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 close [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 close [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: PointerWatcher
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [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()
示例6: call
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [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?"
示例7: writeWord
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [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()
示例8: MouseWatcher
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [as 别名]
class MouseWatcher(Thread):
def __init__(self, listener=MouseListener()):
Thread.__init__(self)
self.m = PyMouse()
self.ui = UInput()
self.devices = []
self.running = True
self.lastPosition = None
self.device_search()
self.listener = listener
def stop(self):
print "Desligando mouse."
self.running = False
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))
keymap = dev.capabilities().get(1)
if ecodes.BTN_MOUSE in keymap and ecodes.BTN_LEFT in keymap:
devices_list.append(dev)
except (IOError, OSError, TypeError):
pass
self.devices = {dev.fd: dev for dev in devices_list}
def run(self):
while self.running:
r,w,x = select(self.devices, [], [])
for fd in r:
if not self.running:
break
for event in self.devices[fd].read():
if event.type == ecodes.EV_KEY and event.value == 1:
self.lastPosition = self.m.position()
if self.listener.__class__ != MouseListener:
self.listener.call_me(self.lastPosition)
self.ui.close()
示例9: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [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()
示例10: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [as 别名]
#.........这里部分代码省略.........
if self.__space_mode:
self.emit_with_space_mode(event)
elif self.__tenkey_mode:
#print("control tenkey")
self.emit_with_tenkey_mode(event)
else:
self.sink.write(ecodes.EV_KEY, event.event.scancode, 1)
self.sink.write(ecodes.EV_KEY, event.event.scancode, 0)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTCTRL, 0)
def emit_with_shift_mode(self, event):
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 1)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 2)
self.sink.write(ecodes.EV_KEY, event.event.scancode, 1)
self.sink.write(ecodes.EV_KEY, event.event.scancode, 0)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 0)
def emit_with_normal_mode(self, event):
self.sink.write(ecodes.EV_KEY, event.event.scancode, event.event.keystate)
def emit(self, event):
#if event.event.scancode == ecodes.KEY_CAPSLOCK:# or event.event.scancode == ecodes.KEY_SYSRQ:
# self.sink.write(ecodes.EV_KEY, ecodes.KEY_F1, event.event.keystate)
#elif event.event.scancode == ecodes.KEY_LEFTMETA and event.event.keystate == events.KeyEvent.key_hold:
# pass
# #self.sink.write(ecodes.EV_KEY, ecodes.KEY_F1, event.event.keystate)
if self.__control_mode and event.event.keystate != events.KeyEvent.key_up:
self.emit_with_control_mode(event)
elif self.__space_mode and event.event.keystate != events.KeyEvent.key_up:
self.emit_with_space_mode(event)
elif self.__shift_mode and event.event.keystate != events.KeyEvent.key_up:
self.emit_with_shift_mode(event)
elif self.__tenkey_mode and event.event.keystate != events.KeyEvent.key_up:
self.emit_with_tenkey_mode(event)
else:
self.emit_with_normal_mode(event)
self.sink.syn()
def emit_space(self):
self.sink.write(ecodes.EV_KEY, ecodes.KEY_SPACE, 1)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_SPACE, 0)
self.sink.syn()
def emit_z(self):
self.sink.write(ecodes.EV_KEY, ecodes.KEY_Z, 1)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_Z, 0)
self.sink.syn()
def emit_slash(self):
if self.__space_mode:
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 1)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 2)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_SLASH, 1)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_SLASH, 0)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 0)
else:
self.sink.write(ecodes.EV_KEY, ecodes.KEY_SLASH, 1)
self.sink.write(ecodes.EV_KEY, ecodes.KEY_SLASH, 0)
self.sink.syn()
def emit_as_buffered(self, event):
self.buffered_event = event
def emit_buffered(self):
self.emit(self.buffered_event)
self.buffered_event = None
def buffer(self, event):
self.emit_as_buffered(event)
def flush(self):
self.emit_buffered()
def reset_state(self):
self.__buffer = None
self.__space_mode = False
self.__control_mode = False
self.__meta_mode = False
self.__tenkey_mode = False
self.__shift_mode = False
def space_mode(self, flag):
self.__space_mode = flag
def control_mode(self, flag):
self.__control_mode = flag
def meta_mode(self, flag):
self.__meta_mode = flag
def shift_mode(self, flag):
self.__shift_mode = flag
def tenkey_mode(self, flag):
self.__tenkey_mode = flag
def close(self):
self.sink.close()
示例11: print
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [as 别名]
i = 5
moves = 100000
print("Go to 2048 window. ["+str(i)+"] secs.")
while i != 0:
print(" " + str(i))
time.sleep(1)
i -= 1
print("Commencing...\n")
keys = ["e.KEY_UP", "e.KEY_DOWN", "e.KEY_LEFT", "e.KEY_RIGHT"]
keys = [105, 106, 103, 108]
# random.choice(foo)
ui = UInput()
current_title = GetActiveWindowTitle()
if 'Firefox' in current_title:
while moves != 0:
temp_key = random.choice(keys)
send_keys(ui, temp_key)
time.sleep(0.1)
moves -= 1
print("Done")
else:
print("You're not on the firefox window.")
ui.close()
示例12: PPMDecoder
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [as 别名]
class PPMDecoder(object):
"""Decodes the audio data into PPM pulse data, and then into uinput
joystick events.
"""
def __init__(self, rate):
"""
Parameters
----------
rate : int
sample rate
"""
self._rate = float(rate)
self._lf = None
self._threshold = 15000
self._last_edge = None
self._ch = None
# Size in sampling intervals, of the frame space marker
self._marker = int(2.0 * 0.0025 * self._rate)
# Mapping of channels to events
self._mapping = {0: ecodes.ABS_X,
1: ecodes.ABS_Y,
2: ecodes.ABS_Z,
3: ecodes.ABS_THROTTLE}
events = [(v, (0, 255, 5, 0)) for v in self._mapping.values()]
self._ev = UInput(name='ppmadapter',
events={
ecodes.EV_ABS: events,
ecodes.EV_KEY: {288: 'BTN_JOYSTICK'}
})
def __enter__(self):
return self
def __exit__(self, type, value, tb):
self._ev.close()
def feed(self, data):
"""Feeds the decoder with a block of sample data.
The data should be integer values, and should only be a single channel.
Parameters
----------
data : list
sample data
"""
sync_req = False
for i in range(len(data)):
this_edge = data[i] > self._threshold
if self._last_edge is None:
self._last_edge = this_edge
continue
if this_edge and not self._last_edge:
# rising
if self._lf is not None:
sync_req |= self.signal(i - self._lf)
elif not this_edge and self._last_edge:
# falling
self._lf = i
self._last_edge = this_edge
if sync_req:
self._ev.syn()
if self._lf is not None:
self._lf = self._lf - len(data)
if self._lf < (-self._rate):
print("Lost sync")
self._ch = None
self._lf = None
def signal(self, w):
"""Process the detected signal.
The signal is the number of sampling intervals between the falling
edge and the rising edge.
Parameters
----------
w : int
signal width
Returns
-------
bool
does uinput require sync
"""
if w > self._marker:
if self._ch is None:
print("Got sync")
self._ch = 0
return False
if self._ch is None or self._ch not in self._mapping:
#.........这里部分代码省略.........
示例13: HIDMapperController
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import close [as 别名]
class HIDMapperController (object):
def __init__ (self):
self._profile = None
self._running = False
self._input_devices = None
self._file_descriptors = None
self._allowed_event_types = None
self._event_status = None
self._gesture_codes = deque()
self._last_queued = None
self._virtual_input = None
self._matcher = None
@property
def profile (self, profile_obj):
self._profile=profile_obj
@profile.setter
def profile (self, profile_obj):
self._profile=profile_obj
def _prepare_device (self):
#print("device: %s" % self._profile.device.name)
self._event_status = {key:0 for key in self._profile.device.get_events_supported()}
#print("Events supported",self._event_status)
self._allowed_event_types = set([getattr(ecodes,i[-1].split(':')[0]) for i in self._event_status])
self._input_devices = map(InputDevice, self._profile.device.devices)
self._file_descriptors = { dev.fd: i for i, dev in enumerate(self._input_devices) }
print("Mappings for '" + self._profile.name+"' " + '-'*30)
for k,v in sorted(self._profile.mapping.items()):
print(str(k.replace("EV_KEY:KEY_","").replace("ENTER","<-'").replace("APOSTROPHE","'").replace(",","")).lower().rjust(20)+" as "+(', '.join(v)).replace("r_hand_tap_", "").replace("_vs_thumb", ""))
# Prepare virtual device for event injection
capabilities = {}
for ev_chain in self._profile.mapping:
for k in re.split('[+,]', ev_chain):
et, ec = k.split(':', 1)
etype = ecodes.ecodes[et]
if etype in capabilities:
capabilities[etype].append(ecodes.ecodes[ec])
else:
capabilities[etype] = [ ecodes.ecodes[ec] ]
#print("Capabilities", capabilities)
self._virtual_input = UInput(events = capabilities)
# Prepare matcher
self._matcher = Matcher(self._profile)
def start (self):
"""
Start capturing from the device(s) of the current profile
"""
self._prepare_device()
try:
for dev in self._input_devices: dev.grab()
except Exception as e:
print("Unable to grab device", e)
self._running = True
spawn(self._capture_loop)
spawn(self._process_loop)
sleep(0)
def stop (self):
"""
Stop capturing and release the device(s)
"""
self._running = False
try:
for dev in self._input_devices: dev.ungrab()
except:
pass
if self._virtual_input:
self._virtual_input.close()
def _capture_loop (self):
try:
devices = {dev.fd : dev for dev in self._input_devices}
while self._running:
r,_,_ = select(devices, [], [], timeout=self._profile.double_click_timeout/1000.0)
for fd in r:
for event in devices[fd].read():
#print("Lo que", event)
if self.is_allowed_event(event, fd):
event_code = self.get_event_code(event, fd)
if event.value == 1:
#print("Pressed!", event_code)
self.set_event_status(event_code, 1)
#print("Statuses", self._event_status)
self._store_gestures()
elif event.value == 0:
#print("Released!", event_code)
self.set_event_status(event_code, 0)
#.........这里部分代码省略.........