本文整理汇总了Python中keyboard.Keyboard.key_to_code方法的典型用法代码示例。如果您正苦于以下问题:Python Keyboard.key_to_code方法的具体用法?Python Keyboard.key_to_code怎么用?Python Keyboard.key_to_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyboard.Keyboard
的用法示例。
在下文中一共展示了Keyboard.key_to_code方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from keyboard import Keyboard [as 别名]
# 或者: from keyboard.Keyboard import key_to_code [as 别名]
#.........这里部分代码省略.........
self.log.debug("%s removed from %s" % (self, desktop))
except ValueError:
pass
del self.windows[wid]
if window in self.win2desk:
del self.win2desk[window]
def on_window_enter(self, evname, xcb_event):
wid = xcb_event.event
if wid not in self.windows:
# self.log.on_window_enter.error("no window with wid=%s" % wid)
self.hook.fire("unknown_window", wid)
return
window = self.windows[wid]
# self.log.on_window_enter("window_enter: %s %s" % (wid, window))
self.hook.fire("window_enter", window)
def grab_key(self, modifiers, key, owner_events=False, window=None):
""" Intercept this key when it is pressed. If owner_events=False then
the window in focus will not receive it. This is useful from WM hotkeys.
"""
# TODO: check if key already grabbed?
# Here is how X works with keys:
# key => keysym => keycode
# where `key' is something like 'a', 'b' or 'Enter',
# `keysum' is what should be written on they key cap (physical keyboard)
# and `keycode' is a number reported by the keyboard when the key is pressed.
# Modifiers are keys like Shift, Alt, Win and some other buttons.
self.log.grab_key.debug("intercept keys: %s %s" % (modifiers, key))
if window is None:
window = self.root
keycode = self.kbd.key_to_code(key)
modmask = get_modmask(modifiers) # TODO: move to Keyboard
event = ("on_key_press", modmask, keycode)
pointer_mode = xproto.GrabMode.Async
keyboard_mode = xproto.GrabMode.Async
self._conn.core.GrabKey(
owner_events,
window.wid,
modmask,
keycode,
pointer_mode,
keyboard_mode
)
self.flush() # TODO: do we need this?
return event
def on_key_press(self, evname, xcb_event):
# TODO: ignore capslock, scrolllock and other modifiers?
modmap = xcb_event.state
keycode = xcb_event.detail
event = ("on_key_press", modmap, keycode)
self.hook.fire(event)
def on_key_release(self, evname, xcb_event):
modmap = xcb_event.state
keycode = xcb_event.detail
event = ("on_key_release", modmap, keycode)
self.hook.fire(event)
def grab_mouse(self, modifiers, button, owner_events=False, window=None):
# http://www.x.org/archive/X11R7.7/doc/man/man3/xcb_grab_button.3.xhtml
wid = (window or self.root).wid
event_mask = xcffib.xproto.EventMask.ButtonPress | \