LINUX.ORG.RU

История изменений

Исправление LINUX-ORG-RU, (текущая версия) :

https://www.linuxjournal.com/article/6429

Вот чуть допиленное sudo app num сколько эвентов показать, если не задавать число то бесконечно.

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

int main(int argc, char *argv[])
{
    size_t rb;
    int fd = 0;
    int inf = 0;
    int num = 0;
    struct input_event ev[64];

    if(argc == 1)
    {
        inf = 1;
    }else{
        num = atoi(argv[1]);
    }
    if(num <= 0){ num=0; }

    for (int i = 0; i < num || inf; ++i)
    {
        rb=read(fd = open("/dev/input/event0",0),ev,sizeof(struct input_event)*64);

        if (rb < (int) sizeof(struct input_event))
        {
            perror("evtest: short read");
            exit (1);
        }

        for (int yalv = 0; yalv < (int) (rb / sizeof(struct input_event)); yalv++)
        {
            if (EV_KEY == ev[yalv].type)
            {
               printf("[%ld.%06ld]",ev[yalv].time.tv_sec,ev[yalv].time.tv_usec);
               printf(" | type %d | code %d | value %d | \n",ev[yalv].type,ev[yalv].code, ev[yalv].value);
            }
        }
        close(fd);
}
    return 0;
}

dron@gnu:~/Рабочий-Стол$ gcc-9 main.c ;sudo ./a.out 6
[1595541942.264725] | type 1 | code 16 | value 1 | 
[1595541942.352054] | type 1 | code 17 | value 1 | 
[1595541942.451097] | type 1 | code 16 | value 0 | 
[1595541942.476870] | type 1 | code 18 | value 1 | 
[1595541942.557378] | type 1 | code 17 | value 0 | 
[1595541942.645395] | type 1 | code 18 | value 0 | 
dron@gnu:~/Рабочий-Стол$

Пригодится комунить

Исправление LINUX-ORG-RU, :

https://www.linuxjournal.com/article/6429

Вот чуть допиленное

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

int main(int argc, char *argv[])
{
    size_t rb;
    int fd = 0;
    int inf = 0;
    int num = 0;
    struct input_event ev[64];

    if(argc == 1)
    {
        inf = 1;
    }else{
        num = atoi(argv[1]);
    }
    if(num <= 0){ num=0; }

    for (int i = 0; i < num || inf; ++i)
    {
        rb=read(fd = open("/dev/input/event0",0),ev,sizeof(struct input_event)*64);

        if (rb < (int) sizeof(struct input_event))
        {
            perror("evtest: short read");
            exit (1);
        }

        for (int yalv = 0; yalv < (int) (rb / sizeof(struct input_event)); yalv++)
        {
            if (EV_KEY == ev[yalv].type)
            {
               printf("[%ld.%06ld]",ev[yalv].time.tv_sec,ev[yalv].time.tv_usec);
               printf(" | type %d | code %d | value %d | \n",ev[yalv].type,ev[yalv].code, ev[yalv].value);
            }
        }
        close(fd);
}
    return 0;
}

dron@gnu:~/Рабочий-Стол$ gcc-9 main.c ;sudo ./a.out 6
[1595541942.264725] | type 1 | code 16 | value 1 | 
[1595541942.352054] | type 1 | code 17 | value 1 | 
[1595541942.451097] | type 1 | code 16 | value 0 | 
[1595541942.476870] | type 1 | code 18 | value 1 | 
[1595541942.557378] | type 1 | code 17 | value 0 | 
[1595541942.645395] | type 1 | code 18 | value 0 | 
dron@gnu:~/Рабочий-Стол$

Пригодится комунить

Исправление LINUX-ORG-RU, :

https://www.linuxjournal.com/article/6429

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

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
  int main()
  {
/* how many bytes were read */
size_t rb;
/* the events (up to 64 at once) */
struct input_event ev[64];


rb=read(open("/dev/input/event0",0),ev,sizeof(struct input_event)*64);

if (rb < (int) sizeof(struct input_event)) {
    perror("evtest: short read");
    exit (1);
}


for (int yalv = 0;
     yalv < (int) (rb / sizeof(struct input_event));
     yalv++)
{
    if (EV_KEY == ev[yalv].type)
        printf("%ld.%06ld ",ev[yalv].time.tv_sec,ev[yalv].time.tv_usec);
        printf("type %d code %d value %d\n",ev[yalv].type,ev[yalv].code, ev[yalv].value);
}

    return 0;
  }
gcc test.c
sudo watch -m 0.01 ./a.out

Пригодится комунить

Исходная версия LINUX-ORG-RU, :

https://www.linuxjournal.com/article/6429

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

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
  int main()
  {
/* how many bytes were read */
size_t rb;
/* the events (up to 64 at once) */
struct input_event ev[64];


rb=read(open("/dev/input/event0",0),ev,sizeof(struct input_event)*64);

if (rb < (int) sizeof(struct input_event)) {
    perror("evtest: short read");
    exit (1);
}


for (int yalv = 0;
     yalv < (int) (rb / sizeof(struct input_event));
     yalv++)
{
    if (EV_KEY == ev[yalv].type)
        printf("%ld.%06ld ",ev[yalv].time.tv_sec,ev[yalv].time.tv_usec);
        printf("type %d code %d value %d\n",ev[yalv].type,ev[yalv].code, ev[yalv].value);
}

    return 0;
  }
gcc test.c
sudo watch -m 0.01 ./a.out