Created
July 21, 2021 19:05
-
-
Save oddlyspaced/2fc2da4492130ee3df0a545dc9ec0588 to your computer and use it in GitHub Desktop.
Print keycode of Mouse and Keyboard presses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <X11/Xlib.h> | |
int main(int argsc, char *argv[]) { | |
// Display | |
Display *dpy; | |
// Screen Id | |
int screen; | |
// Window | |
Window win; | |
// events inside window | |
XEvent event; | |
// Open Display | |
dpy = XOpenDisplay(NULL); | |
// Check is server is not null | |
if (dpy == NULL) { | |
fprintf(stderr, "Cannot open display!\n"); | |
exit(1); | |
} | |
// Connect to screen from server | |
screen = DefaultScreen(dpy); | |
// Basic window qith 500 x 300 size and 100,100 position | |
win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100, 500, 300, 1, BlackPixel(dpy, screen), WhitePixel(dpy, screen)); | |
// Define what Input events to select | |
XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonReleaseMask | ButtonPressMask); | |
// maps the window and all of its subwindows that have map requests | |
XMapWindow(dpy, win); | |
// infinitely read next event | |
while (1) { | |
XNextEvent(dpy, &event); | |
printf("BUTTON: %d\n", event.xkey.keycode); | |
printf("-----------\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment