Created
April 14, 2017 20:48
-
-
Save jahir/a99e0e55c1a1aedb8c776e52c811212a to your computer and use it in GitHub Desktop.
read (midde) mouse button state every 5ms
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 <string.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <linux/input.h> | |
#include <stdint.h> | |
#define test_bit(p, n) !!(p[n>>3] & (1u << (n&7))) | |
int isButtonPressed(int fd, unsigned short code) { | |
uint8_t keys[(KEY_MAX<<3)+1]; | |
memset(keys, 0, sizeof(keys)); | |
ioctl(fd, EVIOCGKEY(sizeof(keys)), keys); | |
return test_bit(keys, code); | |
} | |
int main(int argc, char* argv[]) | |
{ | |
char * dev; | |
int fd; | |
if (argc < 2) { | |
fprintf(stderr, "Usage: %s /dev/input/eventX\n", argv[0]); | |
return 1; | |
} | |
dev = argv[1]; | |
printf("using %s\n", dev); | |
if ((fd = open(dev, O_RDWR)) < 0) { | |
perror("open event device"); | |
return 1; | |
} | |
while (1) { | |
write(1, isButtonPressed(fd, BTN_MIDDLE) ? "X" : ".", 1); | |
usleep(5000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment