Xlib mouse events and ButtonPressMask

Posted by Trilly Campanelino on Stack Overflow See other posts from Stack Overflow or by Trilly Campanelino
Published on 2009-11-27T06:21:02Z Indexed on 2010/03/09 10:21 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

I have written a simple program which will report key press and release events for a particular window. In my case, it is mostly the terminal since I invoke the program from the terminal. I am able to get the key press and release events taking place in the terminal window (I have used XSelectInput() with KeyPressMask and KeyReleaseMask on the terminal) but the same is not working with ButtonPress and ButtonRelease. Not just these, but any events related to the mouse are not being reported. Any idea why this is happening?

#include
#include
#include
#include
#include
#include

int main() {
Display *display = XOpenDisplay(NULL);
KeySym k;
int revert_to;
Window window;
XEvent event;

XGetInputFocus(display, &window, &revert_to);
XSelectInput(display, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);

while(1)
{
XNextEvent(display,&event);
  switch (event.type) {

  case KeyPress : printf("Key Pressed\n"); break;
  case KeyRelease : printf("Key Released\n"); break;
  case ButtonPress : printf("Button Pressed\n"); break;
  case ButtonRelease : printf("Button Released\n"); break;
  case EnterNotify : printf("Enter\n"); break;
  }
}
XCloseDisplay(display);
return 0;
}

© Stack Overflow or respective owner

Related posts about xlib

Related posts about pointer