rshk / python-libxdo

Python bindings for libxdo
BSD 3-Clause "New" or "Revised" License
76 stars 19 forks source link

send_keysequence_window() stops working after switching windows #23

Open hirnwunde opened 5 years ago

hirnwunde commented 5 years ago

Hi folks,

sometimes my pythonscript stops working after switching windows with <Alt>-<Tab>. This happens under DE Cinnamon, KDE Plasma and XFCE4. When i use the same functionality at this point of time via commandline tool xdotool the keystrokes will be sended. When i restart X completely (normal logout/hard <Ctrl>-<Alt>-<Backspace>) the script works again.

Maybe this is wine-related ... i send Keystrokes to a WoW-Window started with wine-4.12.1.r1.gaccf1895 There's also dxvk involved.

Honestly, i don't know what information you need to narrow down the error. here are some details:

pip search libxdo
python-libxdo (0.1.2a1)  - Python bindings for libxdo
 INSTALLED: 0.1.2a1 (latest)

The script i use:

#!/usr/bin/env python3

from pynput import mouse
from xdo import Xdo
import threading

state = 0
thrCnt = 1
windowID = 0
objWin = object()

xdo = Xdo()

if windowID == 0:
    objWin = xdo.search_windows(
        winname=b'World of Warcraft', only_visible=True, require=True)
    windowID = objWin[0]
    print('First start. Set WinID to: ' + str(windowID))

def thread_Sendkey():
    global state
    global windowID
    global objWin

    while state == 1:
        xdo.send_keysequence_window(objWin[0], "2", 80000)

def on_click(x, y, button, pressed):
    global state
    global thrCnt
    v = button.value
    if pressed:
        if v == 8:
            if state == 0:
                thrCnt += 1
                print('start ' + str(thrCnt) + '...')
                x = threading.Thread(target=thread_Sendkey)
                x.start()  # start thread
                state = 1
            else:
                print('end\n---------------------------')
                state = 0

with mouse.Listener(on_click=on_click) as listenerm:
    listenerm.join()