<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: xlib code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Oct 2008 19:25:41 GMT</pubDate>
    <description>DZone Snippets: xlib code</description>
    <item>
      <title>Xlib - mouseClick</title>
      <link>http://snippets.dzone.com/posts/show/2750</link>
      <description>// Simula il click del mouse&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;unistd.h&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;X11/Xlib.h&gt;&lt;br /&gt;#include &lt;X11/Xutil.h&gt;&lt;br /&gt;&lt;br /&gt;void mouseClick(int button)&lt;br /&gt;{&lt;br /&gt;	Display *display = XOpenDisplay(NULL);&lt;br /&gt;&lt;br /&gt;	XEvent event;&lt;br /&gt;	&lt;br /&gt;	if(display == NULL)&lt;br /&gt;	{&lt;br /&gt;		fprintf(stderr, "Errore nell'apertura del Display !!!\n");&lt;br /&gt;		exit(EXIT_FAILURE);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	memset(&amp;event, 0x00, sizeof(event));&lt;br /&gt;	&lt;br /&gt;	event.type = ButtonPress;&lt;br /&gt;	event.xbutton.button = button;&lt;br /&gt;	event.xbutton.same_screen = True;&lt;br /&gt;	&lt;br /&gt;	XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &amp;event.xbutton.root, &amp;event.xbutton.window, &amp;event.xbutton.x_root, &amp;event.xbutton.y_root, &amp;event.xbutton.x, &amp;event.xbutton.y, &amp;event.xbutton.state);&lt;br /&gt;	&lt;br /&gt;	event.xbutton.subwindow = event.xbutton.window;&lt;br /&gt;	&lt;br /&gt;	while(event.xbutton.subwindow)&lt;br /&gt;	{&lt;br /&gt;		event.xbutton.window = event.xbutton.subwindow;&lt;br /&gt;		&lt;br /&gt;		XQueryPointer(display, event.xbutton.window, &amp;event.xbutton.root, &amp;event.xbutton.subwindow, &amp;event.xbutton.x_root, &amp;event.xbutton.y_root, &amp;event.xbutton.x, &amp;event.xbutton.y, &amp;event.xbutton.state);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	if(XSendEvent(display, PointerWindow, True, 0xfff, &amp;event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");&lt;br /&gt;	&lt;br /&gt;	XFlush(display);&lt;br /&gt;	&lt;br /&gt;	usleep(100000);&lt;br /&gt;	&lt;br /&gt;	event.type = ButtonRelease;&lt;br /&gt;	event.xbutton.state = 0x100;&lt;br /&gt;	&lt;br /&gt;	if(XSendEvent(display, PointerWindow, True, 0xfff, &amp;event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");&lt;br /&gt;	&lt;br /&gt;	XFlush(display);&lt;br /&gt;	&lt;br /&gt;	XCloseDisplay(display);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// gcc source.c -L /usr/X11R6/lib -lX11</description>
      <pubDate>Sun, 01 Oct 2006 21:54:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2750</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Xlib - mouseMove</title>
      <link>http://snippets.dzone.com/posts/show/2743</link>
      <description>// muove il mouse alle coordinate currentX + x, currentY + y&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;X11/Xlib.h&gt;&lt;br /&gt;#include &lt;X11/Xutil.h&gt;&lt;br /&gt;&lt;br /&gt;void mouseMove(int x, int y)&lt;br /&gt;{&lt;br /&gt;	Display *displayMain = XOpenDisplay(NULL);&lt;br /&gt;&lt;br /&gt;	if(displayMain == NULL)&lt;br /&gt;	{&lt;br /&gt;		fprintf(stderr, "Errore nell'apertura del Display !!!\n");&lt;br /&gt;		exit(EXIT_FAILURE);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	XWarpPointer(displayMain, None, None, 0, 0, 0, 0, x, y);&lt;br /&gt;&lt;br /&gt;	XCloseDisplay(displayMain);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// gcc source.c -L /usr/X11R6/lib -lX11</description>
      <pubDate>Sat, 30 Sep 2006 16:18:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2743</guid>
      <author>whitetiger ()</author>
    </item>
  </channel>
</rss>
