Note that there are some explanatory texts on larger screens.

plurals
  1. POSending Keystrokes to a X Window
    text
    copied!<p>I am currently experimenting with xdotool to send keys to a process (I understand that it may not work for all processes that does not set _NET_WM_PID). I have trouble sending keystrokes to windows other from the focus. It does work if you are sending keystrokes to the <code>CURRENTWINDOW</code>. Below is the snippet that I used to test xdotool's functionality.</p> <pre><code>extern "C"{ #include &lt;xdo.h&gt; } //extern "C" xdo_window_search #include &lt;iostream&gt; #include &lt;string.h&gt; using namespace std; int main(){ xdo_t* p_xdo = xdo_new(NULL); // Allocate memory for search query. xdo_search_t s; // Clear the allocated memory. memset(&amp;s, 0, sizeof(xdo_search_t)); // Set the search query. s.pid = 1916; s.max_depth = -1; s.searchmask = SEARCH_PID; s.require = xdo_search::SEARCH_ANY; // Allocate memory for output Window* windows; int no_windows; xdo_window_search(p_xdo,&amp;s,&amp;windows,&amp;no_windows); cout &lt;&lt; no_windows &lt;&lt; endl; // Prints all windows' names with matching criteria for( int i=0;i&lt;no_windows;i++ ){ unsigned char * name; int size; int type; xdo_get_window_name(p_xdo,windows[i],&amp;name,&amp;size,&amp;type); cout &lt;&lt; i &lt;&lt; ":" &lt;&lt; name &lt;&lt; endl; } for( int i=0;i&lt;no_windows;i++ ){ xdo_type(p_xdo,windows[i],"Hello World",0); } //xdo_type(p_xdo,CURRENTWINDOW,"Hello World",0); // This does work. return 0; } </code></pre> <p>In additional to testing xdotool's functionality, I've looked into xdotool's source code. Interestingly, I found that they are using Xtest to send keystrokes to the focused window (<code>CURRENTWINDOW</code>) and X11's <code>XSendEvent</code> for other windows. I turned to xdotool because I couldn't get XSendEvent to work and Xtest cannot send keys to any other windows than the focused window.</p> <p>Am I not using the xdotool correctly? Does xdotool not work with all *nix OS with X11?</p> <p>[I am running this on Ubuntu 13.04.]</p> <hr> <p><strong>EDIT</strong></p> <p>So, it looks like that does work but not for all windows that it finds. For example, it works for firefox but not gedit and gnome-terminal although it found gedit and gnome-terminal by its pid. It behaves differently if I used <code>CURRENTWINDOW</code>.</p> <p>So, it would be great if someone can explain why is this so. Like, is it related the force send flag in an XEvent? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload