jordansissel / xdotool

fake keyboard/mouse input, window management, and more
Other
3.17k stars 316 forks source link

xdotool cannot send key combinations to Qt-based applications #453

Open cepamoi opened 5 months ago

cepamoi commented 5 months ago

I am running xdotool 3.20211022.1 on Kubuntu 22.04 (with X11). xdotool works fine with X11/Motif and GTK-based applications.

However, with Qt-based applications, sending key combinations does not work: xdotool key --window 0x04000006 ctrl+o Sending function keys does not work neither: xdotool key --window 0x04000006 "F5" But sending normal keys/chars works fine: xdotool key --window 0x04000006 q

Is there something wrong? Or am I missing something?

Thanks.

FascinatedBox commented 4 months ago

A couple questions come to mind:

cepamoi commented 4 months ago

I find the window for example with the PID (xdotool search --pid XYZ). The window ID is most probably correct because sending normal keys/chars works fine. Only sending key combinations or function keys does not work.

Below is the output of xprop:

_NET_WM_USER_TIME(CARDINAL) = 0 _NET_WM_ICON_GEOMETRY(CARDINAL) = 443, 2104, 64, 56 _NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_CLOSE _KDE_NET_WM_FRAME_STRUT(CARDINAL) = 0, 0, 41, 0 _NET_FRAME_EXTENTS(CARDINAL) = 0, 0, 41, 0 _NET_WM_DESKTOP(CARDINAL) = 0 _KDE_NET_WM_ACTIVITIES(STRING) = "69948556-27b6-40d0-a20c-9ff567d66f7d" WM_STATE(WM_STATE): window state: Normal icon window: 0x0 _NET_WM_STATE(ATOM) = _NET_WM_ICON_NAME(UTF8_STRING) = XdndAware(ATOM) = BITMAP WM_NAME(STRING) = "untitled.txt" _NET_WM_NAME(UTF8_STRING) = "untitled.txt" _KDE_NET_WM_USER_CREATION_TIME(CARDINAL) = 30992558 _MOTIF_WM_HINTS(_MOTIF_WM_HINTS) = 0x3, 0x3e, 0x7e, 0x0, 0x0 _NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL _XEMBED_INFO(_XEMBED_INFO) = 0x0, 0x1 WM_CLIENT_LEADER(WINDOW): window id # 0x5000008 WM_HINTS(WM_HINTS): Client accepts input or input focus: True window id # of group leader: 0x5000008 WM_CLIENT_MACHINE(STRING) = "kobaia" _NET_WM_PID(CARDINAL) = 69546 _NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 83886087 WM_CLASS(STRING) = "application", "Application Example" WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST WM_NORMAL_HINTS(WM_SIZE_HINTS): user specified location: 908, 494 user specified size: 1364 by 785 program specified minimum size: 252 by 279 program specified resize increment: 2 by 2 program specified base size: 0 by 0 window gravity: Static

FascinatedBox commented 4 months ago

You're definitely hitting the right window. Suppose you go into xdo.c, specifically _xdo_send_key, and do this:

-  int use_xtest = 0;

-  if (window == CURRENTWINDOW) {
-    use_xtest = 1;
-  } else {
-    Window focuswin = 0;
-    xdo_get_focused_window(xdo, &focuswin);
-    if (focuswin == window) {
-      use_xtest = 1;
-    }
-  }

+  int use_xtest = 1;

On my system, the non-xtest path doesn't even show keycodes being sent to the application. I can tell because I'm having xev watch the window, and it's getting straight nada. The xtest path, however, results in the app seeing keypresses and they don't show up as synthetic. The latter being particularly important because some applications will straight up ignore synthetic keys.

That is, unfortunately, my only guess for it.

jordansissel commented 4 months ago

@FascinatedBox If you want to explicitly use XTEST, you shouldn't need to patch xdotool. Instead, setting the window to 0 should suffice with most commands supporting this via --window 0 which will override anything in the window stack (from previous commands) and set it back to the default. (I don't think this is documented, though, and may be something to improve in the docs at some point)

cepamoi commented 4 months ago

@FascinatedBox I tried to patch the code as you suggested. But the key I send is just entered in my terminal instead of the requested window.

@jordansissel I tried the following command line: xdotool windowfocus 60817414 key --window 0 ctrl+o But this does not work neither: the window gets the focus as expected, but the key combination is not sent.

But maybe I did something wrong. Any idea? Thanks.