GNU >> C/C++

input_event


參考資訊:
1. input.h

main.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>

int main(int argc, char **argv)
{
    int fd = -1;
    struct input_event ev = {0};

    fd = open("/dev/input/event0", O_RDONLY);
    if (fd > 0) {
        while (read(fd, &ev, sizeof(struct input_event))) {
            if (ev.type == EV_KEY) {
                printf("code:%d, value:%d\n", ev.code, ev.value);
            }
        }
        close(fd);
    }
    return 0;
}

編譯、執行

$ gcc main.c -o main
$ ./main
    code:28, value:0
    code:29, value:1
    code:46, value:1


返回上一頁