0

i want get pressed number via AutoKey. My Script works but is really slow and looks not very good.

May you know a faster way? I need hold down a key some seconds before its recognized.

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 ")

I read here:

System

AutoKey (Qt) 0.95.10
Python 3.8.5
Operating System: Kubuntu 20xx
KDE Plasma Version
SL5net
  • 2,282
  • 4
  • 28
  • 44

1 Answers1

1

If you want to get input form the user using autokey, I think the best approach would be to open a dialog box:

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
Carlos Galdino
  • 302
  • 3
  • 14
  • Your answer works but stop each read with a dialog box. Can't say it's really faster. – SL5net May 07 '21 at 07:15
  • 1
    Cool. Have you thought about using ``xev`` inside autokey to monitor the keypresses instead of using ``keyboard.wait_for_keypress()``? That might do the trick. If you want, I can elaborate a little better in another answer. Let me know. – Carlos Galdino May 10 '21 at 14:21