Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > pl.comp.os.linux.programowanie > #2112

dev/input/event - odczytanie stringa z emulatora klawiatury

Newsgroups pl.comp.os.linux.programowanie
Date 2017-10-10 05:19 -0700
Message-ID <eb435cf4-ae43-4847-a298-6ae0e29abfe3@googlegroups.com> (permalink)
Subject dev/input/event - odczytanie stringa z emulatora klawiatury
From Tinta Tintoski <tintoski@gmail.com>

Show all headers | View raw


pomoże ktoś?

Potrzebuje odczytać stringa z urządzenia emulujacego klawiaturę (rfid reader)

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

static const char *const evval[3] = {
    "RELEASED",
    "PRESSED ",
    "REPEATED"
};

int main(void)
{
    const char *dev = "/dev/input/event3";
    struct input_event ev;
    ssize_t n;
    int fd;

    fd = open(dev, O_RDONLY);
    if (fd == -1) {
        fprintf(stderr, "Cannot open %s: %s.\n", dev, strerror(errno));
        return EXIT_FAILURE;
    }
    
    
       while (1) {
         n = read(fd, &ev, sizeof ev);
         if (n == (ssize_t)-1) {
            if (errno == EINTR)
                continue;
            else
                 break;
         } else
         if (n != sizeof ev) {
             errno = EIO;
             break;
         }
        
        
        if (ev.type == EV_KEY && ev.value >= 0 && ev.value <= 2){
            printf("%s 0x%04x (%d)\n", evval[ev.value], (int)ev.code, (int)ev.code);
        }
            
    }
    
    
    
    
    
    fflush(stdout);
    fprintf(stderr, "%s.\n", strerror(errno));
    return EXIT_FAILURE;
}



jednak podany kod wyświetla mi w pętli dane natomiast ja potrzebuję to w jednej zmiennej. Nie ogarniam c wcale, więc proszę jakąś dobrą duszę o pomoc.

Back to pl.comp.os.linux.programowanie | Previous | NextNext in thread | Find similar


Thread

dev/input/event - odczytanie stringa z emulatora klawiatury Tinta Tintoski <tintoski@gmail.com> - 2017-10-10 05:19 -0700
  Re: dev/input/event - odczytanie stringa z emulatora klawiatury gof@somewhere.invalid (Adam Wysocki) - 2017-10-11 12:29 +0000

csiph-web