Menu

[r239]: / readxkey.c  Maximize  Restore  History

Download this file

78 lines (62 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// 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);
}
}