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


Python UInput.write_event方法代码示例

本文整理汇总了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
开发者ID:EndPointCorp,项目名称:lg_ros_nodes,代码行数:57,代码来源:device_writer.py


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