-
Instale o libnotify-bin, que fornece o comando notify-send
sudo apt-get install libnotify-bin
-
Crie um novo script:
import time import subprocess #no need #keyboard.release_key("<ctrl>") # wait_for_keypress does not return any thing to distinguish between target key pressed or timeout reached. # So if time is less than the timeout then it was key press. start_time = time.time() keyboard.wait_for_keypress("1", timeOut=1) if (time.time()-start_time < 0.9): time.sleep(0.2) window.activate("gnu screen") time.sleep(0.1) active_title = window.get_active_title() # if it doesn't get same title, then no window titled as gnu screen # it sends a notify message otherwise send the key sequence. if (active_title == "gnu screen"): keyboard.press_key("<ctrl>") keyboard.send_key("a") keyboard.release_key("<ctrl>") keyboard.send_key("1") else: subprocess.Popen(['notify-send', "Couldn't find destination window"])
-
Configure sua tecla de atalho como: Ctrl + a
Para acionar: Ctrl + a e 1 (em & lt; 1seg)
Depurar
-
Inicie o X Event Tester na janela do terminal separada
xev -event keyboard
-
Verifique o título da janela, o meu mostra
Event Tester
$ wmctrl -l 0x03000012 -1 N/A Desktop — Plasma 0x030000c1 -1 N/A Desktop — Plasma 0x0300001b -1 N/A Plasma 0x06a00098 0 PC User User - Ask Ubuntu - Mozilla Firefox 0x01a00067 0 N/A user : screen 0x01a000cd 0 N/A user : xev 0x04600001 0 N/A Event Tester 0x01e0015d 0 PC AutoKey
-
Modifique o script para segmentar a janela
Event Tester
.import time import subprocess start_time = time.time() keyboard.wait_for_keypress("1", timeOut=1) if (time.time()-start_time < 0.9): time.sleep(0.2) window.activate("Event Tester") time.sleep(0.1) keyboard.press_key("<ctrl>") keyboard.send_key("a") keyboard.release_key("<ctrl>") keyboard.send_key("1")
-
Se
xev
receber a sequência de teclas. Sua saída deve ser algo semelhante a:KeyPress event, serial 34, synthetic NO, window 0x4600001, root 0xb2, subw 0x0, time 55057700, (1053,140), root:(945,303), state 0x0, keycode 105 (keysym 0xffe4, Control_R), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyPress event, serial 34, synthetic YES, window 0x4600001, root 0xb2, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 38 (keysym 0x61, a), same_screen YES, XLookupString gives 1 bytes: (61) "a" XmbLookupString gives 1 bytes: (61) "a" XFilterEvent returns: False KeyRelease event, serial 35, synthetic YES, window 0x4600001, root 0xb2, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 38 (keysym 0x61, a), same_screen YES, XLookupString gives 1 bytes: (61) "a" XFilterEvent returns: False KeyRelease event, serial 35, synthetic NO, window 0x4600001, root 0xb2, subw 0x0, time 55057701, (1053,140), root:(945,303), state 0x4, keycode 105 (keysym 0xffe4, Control_R), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False KeyPress event, serial 35, synthetic YES, window 0x4600001, root 0xb2, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES, XLookupString gives 1 bytes: (31) "1" XmbLookupString gives 1 bytes: (31) "1" XFilterEvent returns: False KeyRelease event, serial 35, synthetic YES, window 0x4600001, root 0xb2, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES, XLookupString gives 1 bytes: (31) "1" XFilterEvent returns: False
Note que removi a condição if
para verificar o título ativo. O script ativa / aumenta a janela xev, mas a verificação não encontra o título correto. Eu recebi apenas a mensagem de notificação.