### 5.2 Selecting Events

To avoid flooding the clients with events in which they have no interest, they must explicitly tell the server which events they are interested in. This is done by providing the `event_mask` attribute when creating windows with `Window.create_window` or in calls to `Window.change_attributes`. The value of this attribute is a mask of all types of events the client is interested in on that particular window. Whenever the server generates an event for a window which matches the clients event mask on that window, the event will be sent to the client.

The following table lists all event masks and the corresponding event types and classes. All event masks and types are integer constants defined in the module `Xlib.X`. Classes have the same name as the event type, and are defined in `Xlib.protocol.event`.

Mask | Type and Class | Generated when
ButtonMotionMask Button1MotionMask Button2MotionMask Button3MotionMask Button4MotionMask Button5MotionMask | MotionNotify | Pointer moved with any or a certain button down
ButtonPressMask | ButtonPress | Pointer button pressed
ButtonReleaseMask | ButtonRelease | Pointer button released
ColormapChangeMask | ColormapNotify | Colormap changed or installed
EnterWindowMask | EnterNotify | Pointer enters window
LeaveWindowMask | LeaveNotify | Pointer leaves window
ExposureMask | Expose NoExpose | Window needs to be redrawn
FocusChangeMask | FocusIn FocusOut | Focus changes
KeymapStateMask | KeymapNotify | After EnterNotify and FocusIn
KeyPressMask | KeyPress | Key is pressed
KeyReleaseMask | ReleasePress | Key is released
PointerMotionMask | MotionNotify | Pointer is moved
PropertyChangeMask | PropertyNotify | Window properties change
StructureNotifyMask | CirculateNotify ConfigureNotify DestroyNotify GravityNotify MapNotify ReparentNotify UnmapNotify | Window structure changes
SubstructureNotifyMask | CirculateNotify ConfigureNotify CreateNotify DestroyNotify GravityNotify MapNotify ReparentNotify UnmapNotify | Child window structure changes
ResizeRedirectMask | ResizeRequest | Controlling window size change
SubstructureRedirectMask | CirculateRequest ConfigureRequest MapRequest | Controlling changes to child windows
VisibilityChangeMask | VisibilityNotify | Window is obscured or visible

There are also some event types which are always sent to the clients, regardless of any event masks:

Type and Class | Cut’n’pasting between windows
ClientMessage | Other client sends message
MappingMotify | Keyboard mapping changes
SelectionClear SelectionNotify SelectionRequest | Cut’n’pasting between windows