ubuntu - 使用 AutoKey 读取数字很慢

标签 ubuntu kde-plasma autokey

我想通过 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 ")

我在这里读到:
  • https://autokey.github.io/lib.scripting-pysrc.html
  • https://github.com/autokey/autokey
  • 当然还有网络上的一些地方

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

    最佳答案

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

    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
    

    关于ubuntu - 使用 AutoKey 读取数字很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65589400/

    相关文章:

    c++ - Qt Designer/Qt Creator/KDevelop 中的 KDE4 小部件

    python - 在 KDE Python 应用程序中处理 KeyboardInterrupt?

    python - 在 Linux 中获取和设置 X11 剪贴板

    python - 将自动 keystore 导入 python 脚本的任何方法

    linux - 我想打印 1 个版本的重复项并删除 bash linux 中的唯一行

    android - 通过 Ubuntu 在 xperia 上调试应用程序

    c - 无法编译包含问题的 C 代码

    Perl 无法安装 Net::SSL

    linux - 有没有办法在 Eclipse 中更改一些 "special"GUI 颜色?

    git - 无法通过 HTTP 使用 Git 进行克隆