C에서 모든 마우스 및 키보드 이벤트를 캡처하려는 간단한 프로그램을 작성 중입니다. "XGrapPointer"를 사용하려고했지만 화면이 잠겨서 다른 응용 프로그램으로 이동할 수 없습니다. "XSelectInput()"으로 시도했지만 키보드 이벤트가 성공적으로 수신되고 있지만 마우스 클릭 이벤트가 발생하지 않습니다.XSelectInput이 ButtonPressEvents에 대해 작동하지 않습니다. 어떻게해야합니까?
내가 어떻게 할 수 있습니까? 다음과 같이
코드 조각은 다음과 같습니다
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
int main(int argc, char **argv)
{
Display *dpy;
Window root;
unsigned long event_mask;
event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask;
if((dpy = XOpenDisplay(NULL)) == NULL) {
perror(argv[0]);
exit(1);
}
dpy = XOpenDisplay(NULL);
root = XDefaultRootWindow(dpy);
int state;
XWindowAttributes attributes;
XGetInputFocus(dpy,&root,&state);
printf("window id = %d\n");
XSelectInput(dpy,root,event_mask);
XEvent ev;
while(1) {
XNextEvent(dpy, &ev);
if(ev.type==ButtonRelease){
printf("button release\n");
}
if (ev.type== KeyPress) {
printf("keypress event\n");
}
}
return 0;
}
이것은 현대 X11 서버/창 관리자에서는 작동하지 않습니다. [BadAccess] (http://stackoverflow.com/questions/16122196/getting-mouseclick-coordinates-with-xlib) 오류가 발생합니다. –
"한 번에 하나의 클라이언트 만 이벤트 마스크 ButtonPressMask와 연결된 ButtonPress 이벤트를 선택할 수 있습니다." BadAccess 오류가 발생하지 않으면 WM이 가상 루트를 구현하고있는 것입니다. 가상 루트는 모든 마우스 이벤트를 가져오고 실제 루트는 아무 것도 얻지 못합니다. –