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


Python GPS.send_key_event方法代码示例

本文整理汇总了Python中GPS.send_key_event方法的典型用法代码示例。如果您正苦于以下问题:Python GPS.send_key_event方法的具体用法?Python GPS.send_key_event怎么用?Python GPS.send_key_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GPS的用法示例。


在下文中一共展示了GPS.send_key_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_key_event

# 需要导入模块: import GPS [as 别名]
# 或者: from GPS import send_key_event [as 别名]
    def send_key_event(keyval, primary=0, alt=0, shift=0, control=0,
                       window=None,
                       process_events=True, bypass_keymanager=False,
                       hardware_keycode=None):
        """Emit a key event on GPS, simulating the given key. This event is
           sent asynchronously.
           Unless process_events is true, this function will return when the
           event has not yet been processed by gtk+.
           keyval is generally the result of calling  ord("x").
           Sending letters to an editor doesn't seem to work at the moment,
           except for special characters like GDK_RETURN.
           If bypass_keymanager is True, do not use the Ada function which
           passes the event to the key manager, but synthesize the event
           in Python directly.
        """
        if not bypass_keymanager:
            if hasattr(GPS, "send_key_event"):
                GPS.send_key_event(keyval, window=window,
                                   primary=primary, control=control,
                                   alt=alt, shift=shift)
                return

        def _synthesize(type, keyval):
            event = Gdk.EventKey()
            event.type = type

            event.window = window
            event.keyval = keyval
            event.send_event = 0
            event.length = 1
            event.is_modifier = 0
            event.group = 0
            event.state = Gdk.ModifierType(0)

            if hardware_keycode:
                event.hardware_keycode = hardware_keycode
            elif keyval == GDK_BACKSPACE:
                event.hardware_keycode = GDK_BACKSPACE_HARDWARE_KEYCODE

            # Can't set string in some versions of pygobject
            # hardware_keycode is OS and keyboard specific.
            # Neither of these are needed in any case.

            return event

        if not window:
            window = [w for w in Gtk.Window.list_toplevels()
                      if w.get_window()][0]
        if isinstance(window, Gtk.TextView):
            window = window.get_window(Gtk.TextWindowType.TEXT)
        if not isinstance(window, Gdk.Window):
            window = window.get_window()

        event = _synthesize(Gdk.EventType.KEY_PRESS, keyval)

        if primary:
            if sys.platform == 'darwin':
                event.state |= Gdk.ModifierType.META_MASK
            else:
                event.state |= Gdk.ModifierType.CONTROL_MASK

        if control:
            event.state |= Gdk.ModifierType.CONTROL_MASK

            # Synthesize the pressing of the control key
            e2 = _synthesize(Gdk.EventType.KEY_PRESS, GDK_CONTROL_L)
            e2.put()

        if shift:
            event.state |= Gdk.ModifierType.SHIFT_MASK
        if alt:
            event.state |= Gdk.ModifierType.MOD1_MASK

        event.put()

        e3 = _synthesize(Gdk.EventType.KEY_RELEASE, keyval)
        e3.state = event.state
        e3.put()

        if control:
            e4 = _synthesize(Gdk.EventType.KEY_RELEASE, GDK_CONTROL_L)
            e4.state = event.state   # matches what gtk+ does
            e4.put()

        if process_events:
            process_all_events()
开发者ID:MichelKramer31,项目名称:gps,代码行数:88,代码来源:__init__.py


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