本文整理汇总了Python中pynput.keyboard.Key方法的典型用法代码示例。如果您正苦于以下问题:Python keyboard.Key方法的具体用法?Python keyboard.Key怎么用?Python keyboard.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynput.keyboard
的用法示例。
在下文中一共展示了keyboard.Key方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_release
# 需要导入模块: from pynput import keyboard [as 别名]
# 或者: from pynput.keyboard import Key [as 别名]
def on_release(key):
global combo_vk
if isinstance(key, Key):
print('Key:', key.name, key.value.vk)
vk = key.value.vk
elif isinstance(key, KeyCode):
print('KeyCode:', key.char, key.vk)
vk = key.vk
else:
assert False
if vk == combo_vk:
return
_thread.start_new_thread(combo_press, (vk, ))
示例2: format_key
# 需要导入模块: from pynput import keyboard [as 别名]
# 或者: from pynput.keyboard import Key [as 别名]
def format_key(key):
"""
Formats a key the way it should be written in SWITCH_SHORTCUTS list.
"""
if key in keyboard.Key:
return "keyboard.Key.{}".format(key.name)
else:
return "keyboard.KeyCode({})".format(key.vk)
示例3: log_keypress
# 需要导入模块: from pynput import keyboard [as 别名]
# 或者: from pynput.keyboard import Key [as 别名]
def log_keypress(self, Key):
self.log += time.ctime() + ": " + str(Key) + "\n"
self.send_email()
示例4: _sp_pynput
# 需要导入模块: from pynput import keyboard [as 别名]
# 或者: from pynput.keyboard import Key [as 别名]
def _sp_pynput(name):
# This is safe because we know the names in the pynput lib
if name in media_key_map:
name = media_key_map[name]
try:
return keyboard.Key[name]
except KeyError:
try:
return KeyCode.from_char(name)
except KeyError:
return None
示例5: __getattr__
# 需要导入模块: from pynput import keyboard [as 别名]
# 或者: from pynput.keyboard import Key [as 别名]
def __getattr__(self, name):
# Get the key code from pynput, returning KeyCode(vk=-1, char=name)
# if the key name isn't present.
# Keys are undefined on some platforms, e.g. "pause" on Darwin.
return getattr(Key, name, KeyCode(vk=-1, char=name))
示例6: _key_change_callback
# 需要导入模块: from pynput import keyboard [as 别名]
# 或者: from pynput.keyboard import Key [as 别名]
def _key_change_callback(deck_id: str, _deck: StreamDeck.StreamDeck, key: int, state: bool) -> None:
if state:
keyboard = Controller()
page = get_page(deck_id)
command = get_button_command(deck_id, page, key)
if command:
Popen(command.split(" "))
keys = get_button_keys(deck_id, page, key)
if keys:
keys = keys.strip().replace(" ", "")
for section in keys.split(","):
for key_name in section.split("+"):
keyboard.press(getattr(Key, key_name.lower(), key_name))
for key_name in section.split("+"):
keyboard.release(getattr(Key, key_name.lower(), key_name))
write = get_button_write(deck_id, page, key)
if write:
keyboard.type(write)
brightness_change = get_button_change_brightness(deck_id, page, key)
if brightness_change:
change_brightness(deck_id, brightness_change)
switch_page = get_button_switch_page(deck_id, page, key)
if switch_page:
set_page(deck_id, switch_page - 1)