<HTML> <HEAD> <!-- Created by texi2html 1.56k from ../src/python-xlib.texi on 22 October 2013 --> <TITLE>The Python X Library - Sending Events</TITLE> </HEAD> <BODY> Go to the <A HREF="python-xlib_1.html">first</A>, <A HREF="python-xlib_13.html">previous</A>, <A HREF="python-xlib_15.html">next</A>, <A HREF="python-xlib_25.html">last</A> section, <A HREF="python-xlib_toc.html">table of contents</A>. <P><HR><P> <H2><A NAME="SEC13" HREF="python-xlib_toc.html#TOC13">Sending Events</A></H2> <P> Clients can send events to each other. Most often these are general-purpose <CODE>ClientMessage</CODE> events, but any event type can be sent. <P> To send an event, an event object must be created. This is done by instantiating an event class, providing values to all its fields as keyword parameters. The event is then sent with the <CODE>send_event()</CODE> method: <P> <DL> <DT><U>Method:</U> Window <B>send_event</B> <I>( event, event_mask = 0, propagate = 0, onerror = None )</I> <DD><A NAME="IDX173"></A> <P> Send <VAR>event</VAR> to this window. <P> If <VAR>event_mask</VAR> is 0, the event is sent to the client that created the window. Otherwise the event is sent to every client selecting any of the event types in <VAR>event_mask</VAR>. <P> If no clients have selected any of the event types and <VAR>propagate</VAR> is true, the X server will search for an ancestor of this window on which some client has selected any of the event types. For details, see XSendEvent(3X11). </DL> <P> <DL> <DT><U>Method:</U> Display <B>send_event</B> <I>( destination, event, event_mask = 0, propagate = 0, onerror = None )</I> <DD><A NAME="IDX174"></A> <P> Send <VAR>event</VAR> to <VAR>destination</VAR>, which can either be a <CODE>Window</CODE> object or a constant: If <CODE>X.PointerWindow</CODE> is specified, send the event to the window the pointer is in. If <CODE>X.InputFocus</CODE> is specified and the focus window contains the pointer, send the event to the window that the pointer is in. Otherwise, send the event to the focus window. </DL> <P> As an example, this creates and sends a <CODE>ClientMessage</CODE> event of the client specific type <CODE>HELLO_WORLD</CODE> (an atom), to the window <CODE>dest</CODE> and with the 8-bitformat value <CODE>"G'day, mate"</CODE> (which must be exactly twenty bytes): <PRE> cm_event = Xlib.protocol.event.ClientMessage( window = dest, client_type = HELLO_WORLD, data = (8, "G'day mate\0\0\0\0\0\0\0\0\0\0")) dest.send_event(cm_event) </PRE> <P><HR><P> Go to the <A HREF="python-xlib_1.html">first</A>, <A HREF="python-xlib_13.html">previous</A>, <A HREF="python-xlib_15.html">next</A>, <A HREF="python-xlib_25.html">last</A> section, <A HREF="python-xlib_toc.html">table of contents</A>. </BODY> </HTML>