1

howto wait for key pressed with autokey?

for AutoKey i found the wait_for_keypress but its not what i searching for.

its wait for a defined keypress or key combination.

i want wait for a,b,... z is pressed.

i searched here:

and tried soe of this exaples without success:

i seached the web for

  • autokey -autohotkey keywait manual
SL5net
  • 2,282
  • 4
  • 28
  • 44

1 Answers1

1

the following solution only works with root rights:

sudo apt install python3-pip
pip3 install keyboard
sudo autokey

then this works (tested in Kubuntu 20.04, see Details below):

import keyboard as keyboard2 # must be different name becouse of name conflicts
while True:
    key = keyboard2.read_key()
    if keyboard2.is_pressed(' '): 
        keyboard.send_keys("You pressed space")
    if key == "p":
        break

tested with:

Operating System: Kubuntu 20.04
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8
SL5net
  • 2,282
  • 4
  • 28
  • 44
  • On ubuntu 16.04 i had to set `xhost +` to run autokey with sudo and it still throws `ModuleNotFoundError` on keyboard import – Karolius May 14 '22 at 12:30