本文整理汇总了Python中evdev.UInput.write_event方法的典型用法代码示例。如果您正苦于以下问题:Python UInput.write_event方法的具体用法?Python UInput.write_event怎么用?Python UInput.write_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evdev.UInput
的用法示例。
在下文中一共展示了UInput.write_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from evdev import UInput [as 别名]
# 或者: from evdev.UInput import write_event [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