Python 中的映射字符串?如何仅按键盘按钮粘贴字符串?

问题描述 投票:0回答:1

如何将字符串链接到 kwyboard 的特定按钮,以便在用户每次按下时粘贴该字符串?字符串粘贴到的位置取决于光标所在的位置,可以是 Word、记事本、浏览器等。可以用Python写吗?

python-3.x operating-system
1个回答
0
投票

如果我可以做任何事情来改进我的答案,请告诉我。

既然您提到字符串可能需要粘贴到浏览器中或光标所在的任何位置,我决定使用模块 pynput 和键盘。我发现键盘通常可以在网络浏览器和其他平台上使用。这是我使用 pynput 和键盘想出的东西:

from pynput.keyboard import Key, Listener
import keyboard

def check(key):
    if key == Key.enter: #I used the key enter but it can be whatever
        keyboard.write('Whatever your string is')


with Listener(on_press = check) as listener:
    listener.join()

有关更多信息,我建议查看键盘和 pynput 中的文档。我希望这能回答您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.