本文整理汇总了Python中evdev.UInput类的典型用法代码示例。如果您正苦于以下问题:Python UInput类的具体用法?Python UInput怎么用?Python UInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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()
示例2: __init__
def __init__(self):
self.ui = UInput()
cap = {e.EV_REL: [e.REL_X, e.REL_Y]}
cap = {
e.EV_REL : (e.REL_X, e.REL_Y),
e.EV_KEY : (e.BTN_MOUSE,),
}
self.mouse = UInput(cap)
示例3: read_data
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
示例4: __init__
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
示例5: create_device
def create_device(self, layout):
events = {ecodes.EV_ABS: [], ecodes.EV_KEY: [],
ecodes.EV_REL: []}
# Joystick device
if layout.axes or layout.buttons or layout.hats:
self.joystick_dev = next_joystick_device()
for name in layout.axes:
key = getattr(ecodes, name)
params = layout.axes_options.get(name, (0, 255, 0, 15))
events[ecodes.EV_ABS].append((key, params))
for name in layout.hats:
key = getattr(ecodes, name)
params = (-1, 1, 0, 0)
events[ecodes.EV_ABS].append((key, params))
for name in layout.buttons:
events[ecodes.EV_KEY].append(getattr(ecodes, name))
if layout.mouse:
self.mouse_pos = {}
for name in layout.mouse:
events[ecodes.EV_REL].append(getattr(ecodes, name))
self.device = UInput(name=layout.name, events=events,
bustype=layout.bustype, vendor=layout.vendor,
product=layout.product, version=layout.version)
self.layout = layout
示例6: create_mouse
def create_mouse(self):
events = {
ecodes.EV_REL: (ecodes.REL_X, ecodes.REL_Y),
ecodes.EV_KEY: (ecodes.BTN_LEFT, ecodes.BTN_RIGHT)
}
self.mouse = UInput(events)
self.mouse_pos = None
示例7: create_device
def create_device(self, layout):
events = {ecodes.EV_ABS: [], ecodes.EV_KEY: [],
ecodes.EV_REL: []}
# Joystick device
if layout.axes or layout.buttons or layout.hats:
self.joystick_dev = next_joystick_device()
for name in layout.axes:
params = layout.axes_options.get(name, DEFAULT_AXIS_OPTIONS)
events[ecodes.EV_ABS].append((name, params))
for name in layout.hats:
params = (-1, 1, 0, 0)
events[ecodes.EV_ABS].append((name, params))
for name in layout.buttons:
events[ecodes.EV_KEY].append(name)
if layout.mouse:
self.mouse_pos = {}
self.mouse_rel = {}
self.mouse_analog_sensitivity = float(layout.mouse_options.get("MOUSE_SENSITIVITY", 0.3))
self.mouse_analog_deadzone = int(layout.mouse_options.get("MOUSE_DEADZONE", 5))
for name in layout.mouse:
events[ecodes.EV_REL].append(name)
self.mouse_rel[name] = 0.0
self.device = UInput(name=layout.name, events=events,
bustype=layout.bustype, vendor=layout.vendor,
product=layout.product, version=layout.version)
self.layout = layout
示例8: __init__
def __init__(self, n, m):
Thread.__init__(self)
self.n = n
self.stop = False
self.sleep = False
self.ui = UInput()
self.m = m
示例9: __init__
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'}
})
示例10: _prepare_device
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)
示例11: writeWord
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: executaAcao
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()
示例13: create_device
def create_device(self, layout):
"""Creates a uinput device using the specified layout."""
events = {ecodes.EV_ABS: [], ecodes.EV_KEY: [],
ecodes.EV_REL: []}
# Joystick device
if layout.axes or layout.buttons or layout.hats:
self.joystick_dev = next_joystick_device()
for name in layout.axes:
params = layout.axes_options.get(name, DEFAULT_AXIS_OPTIONS)
if not absInfoUsesValue:
params = params[1:]
events[ecodes.EV_ABS].append((name, params))
for name in layout.hats:
params = (0, -1, 1, 0, 0)
if not absInfoUsesValue:
params = params[1:]
events[ecodes.EV_ABS].append((name, params))
for name in layout.buttons:
events[ecodes.EV_KEY].append(name)
if layout.mouse:
self.mouse_pos = {}
self.mouse_rel = {}
self.mouse_analog_sensitivity = float(
layout.mouse_options.get("MOUSE_SENSITIVITY",
DEFAULT_MOUSE_SENSITIVTY)
)
self.mouse_analog_deadzone = int(
layout.mouse_options.get("MOUSE_DEADZONE",
DEFAULT_MOUSE_DEADZONE)
)
self.scroll_repeat_delay = float(
layout.mouse_options.get("MOUSE_SCROLL_REPEAT_DELAY",
DEFAULT_SCROLL_REPEAT_DELAY)
)
self.scroll_delay = float(
layout.mouse_options.get("MOUSE_SCROLL_DELAY",
DEFAULT_SCROLL_DELAY)
)
for name in layout.mouse:
if name in (ecodes.REL_WHEELUP, ecodes.REL_WHEELDOWN):
if ecodes.REL_WHEEL not in events[ecodes.EV_REL]:
# This ensures that scroll wheel events can work
events[ecodes.EV_REL].append(ecodes.REL_WHEEL)
else:
events[ecodes.EV_REL].append(name)
self.mouse_rel[name] = 0.0
self.device = UInput(name=layout.name, events=events,
bustype=layout.bustype, vendor=layout.vendor,
product=layout.product, version=layout.version)
self.layout = layout
示例14: __init__
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
示例15: execute
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()