// gcc readxkey.c -lX11 -L/usr/X11/lib
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>
#define EVENT_MASK (ButtonPressMask | KeyPressMask | ExposureMask | StructureNotifyMask)
#define BORDER_WIDTH 8
#define TRUE 1
#define FALSE 0
unsigned long black,white;
Display *display;
main()
{
Window window;
int x,y,width,height;
Visual *visual = CopyFromParent;
XEvent event;
int done=TRUE;
XSetWindowAttributes attributes;
unsigned long attr_mask;
display = XOpenDisplay((char *) NULL);
black = BlackPixel(display,DefaultScreen(display));
white = WhitePixel(display,DefaultScreen(display));
x =0;
y = 0;
width = 800;
height = 600;
attributes.event_mask = EVENT_MASK;
attributes.border_pixel = black;
attributes.background_pixel = white;;
attr_mask = CWEventMask | CWBackPixel | CWBorderPixel ;
window =
XCreateWindow(display,DefaultRootWindow(display),x,y,width,
height,BORDER_WIDTH,CopyFromParent,InputOutput,visual,attr_mask,&attributes);
XSelectInput(display,window,(long)EVENT_MASK);
XMapRaised(display,window);
XFlush(display);
do{
XNextEvent(display,&event);
}while(TakeEvents(event));
XCloseDisplay(display);
exit(0);
}
TakeEvents(event)
XEvent event;
{ XKeyEvent *t;
t=&event;
printf("EVENT TYPE %d",event.type);
//KdEnqueueKeyboardEvent((123-108)& 0x7f,(123-108)& 0x80);
switch (event.type){
case KeyPress:
// printf("We got the key event x:%d y:%d code:%d\n",t->x,t->y,t->keycode);
// printf("We got the key event x:%d y:%d code:%d shift:%u\n",t->x,t->y,t->keycode,t->state&ShiftMask);
printf("We got the key event x:%d y:%d code:%d state:%u\n",t->x,t->y,t->keycode,t->state);
// printf("We got the key event\n");
return(1);
default:
printf("Event!\n");
return(1);
}
}