本文整理匯總了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)