title: How can I control mouse movement in Linux?
body: <p>I try to control the mouse in Linux. Xlib seems to work, but when I try to use it with <a href="https://en.wikipedia.org/wiki/OpenCV" rel="nofollow noreferrer">OpenCV</a>, it keeps returning:</p>
  <pre class="lang-none prettyprint-override"><code>Resource temporarily unavailable
  </code></pre>
  <p>So I decided to write &quot;/dev/psaux&quot;. The code is as follows:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  
  
  int main() {
      unsigned char a[5] = {0, 0xff, 0, 0x28, 0xff};
      int fp = open (&quot;/dev/psaux&quot;, O_WRONLY);
      if(!fp)
          printf(&quot;open error:%s\n&quot;, strerror(errno));
  
      for(int i = 0; i &lt; 10; i++)
          printf(&quot;write:%d\t\t%s\n&quot;, write(fp, a, 5), strerror(errno));
      close(fp);
      return 0;
  }
  </code></pre>
  <p>Compile it with:</p>
  <pre class="lang-none prettyprint-override"><code>gcc  my_psaux.c -o my_psaux -std=gnu99 -g
  </code></pre>
  <p>Run</p>
  <pre class="lang-none prettyprint-override"><code>sudo ./my_psaux
  </code></pre>
  <p>and get</p>
  <pre class="lang-none prettyprint-override"><code>write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  write:5    Success
  </code></pre>
  <p>However, the mouse doesn't move. Then I open a new terminal, type in &quot;sudo cat /dev/psaux&quot; and run &quot;my_psaux&quot;. But I just cat nothing. <strong>Nothing is written into &quot;/dev/psaux&quot;</strong></p>
  <p>How can I fix this?</p>
  <p>If this is not a good method to control the mouse, is there another one?</p>