【问题标题】:Reading numbers with AutoKey is slow使用 AutoKey 读取数字很慢
【发布时间】:2021-04-11 19:45:48
【问题描述】:

我想通过 AutoKey 获得按下的数字。 我的脚本可以运行,但速度很慢,而且看起来不太好。

你知道更快的方法吗?我需要按住一个键几秒钟才能识别它。

import os, time, subprocess 
def popupNotify(text):
    subprocess.Popen(['notify-send', text])  # will be showed right top
pressed_key = 999999999999
for x in range(0, 150):
    retCode1 = keyboard.wait_for_keypress('<np_end>',modifiers=[],timeOut=0.01) # <== works
    retCode2 = keyboard.wait_for_keypress('<np_down>',modifiers=[],timeOut=0.01) # <== works
    retCode3 = keyboard.wait_for_keypress('<np_page_down>',modifiers=[],timeOut=0.01) # <== works
    retCode4 = keyboard.wait_for_keypress('<np_left>',modifiers=[],timeOut=0.001) # <== works
    #retCode5 = keyboard.wait_for_keypress('5',modifiers=[],timeOut=0.001) # <== works
    #retCode5 = keyboard.wait_for_keypress('<code84>',modifiers=[],timeOut=0.001) # <== not works, no error
    if retCode1:
        pressed_key = 1
    if retCode2:
        pressed_key = 2
    if retCode3:
        pressed_key = 3
    if retCode4:
        pressed_key = 4
    if pressed_key != 999999999999:
        break

popupNotify(str(pressed_key))
popupNotify("END END END END ")

我在这里读到:

系统

AutoKey (Qt) 0.95.10
Python 3.8.5
Operating System: Kubuntu 20xx
KDE Plasma Version

【问题讨论】:

    标签: ubuntu kde autokey


    【解决方案1】:

    如果您想使用自动键从用户那里获取输入,我认为最好的方法是打开一个对话框:

    import subprocess
    a = dialog.input_dialog(title='Enter a value', message='Enter a value', default='')
    subprocess.Popen(['notify-send', a.data])  # will be showed right top
    

    【讨论】:

    • 您的答案有效,但每次阅读都会出现一个对话框。不能说它真的更快。
    • 酷。您是否考虑过在 autokey 中使用 xev 而不是使用 keyboard.wait_for_keypress() 来监视按键?这可能会奏效。如果您愿意,我可以在另一个答案中详细说明。告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    相关资源
    最近更新 更多