title: Automation using xdotool and Xvfb
body: <p>I'm trying to automate getting CPU sampler data from visualvm on production system. But to do this I need a way to automate tasks inside Xvfb.</p>
  
  <p>I found that xdotool is good for such automation.
  Right now I have following script:</p>
  
  <pre><code>Xvfb $DISPLAY -pixdepths 32 -screen 0 1280x1024x24 &gt;/dev/null 2&gt;&amp;1 &amp; XPID=$!
  
  echo "Before twm"
  #twm -display $DISPLAY &amp;
  gnome-wm &amp;
  
  #$VISUALVM --openpid $PID_TO_OPEN &amp;
  
  echo "Before gimp"
  gimp &amp;
  
  sleep 5
  xdotool search "GNU.*" windowactivate windowfocus key alt+f n
  
  sleep 3
  DISPLAY=:0.0
  xwd -display :9.0 -root | xwdtopnm | pnmtopng &gt; out.png
  
  qiv out.png
  </code></pre>
  
  <p>It should open Xvfb, run gimp, and click File->New. It does that when I do it in normal X, but when I execute this script in Xvfb it looks like it doesn't pass keyboard events.
  I tested it with mouse and it's the same, xdotool doesn't pass (or Xvfb doesn't accept) events from mouse.</p>
  
  <p>Has anyone encoundered this problem and know a solution?</p>