🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.os.linux.programowanie
2 messages
2 total messages Started by Tinta Tintoski Tue, 10 Oct 2017 12:19
dev/input/event - odczytanie stringa z emulatora klawiatury
#72839
Author: Tinta Tintoski
Date: Tue, 10 Oct 2017 12:19
64 lines
2725 bytes
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.
Re: dev/input/event - odczytanie stringa z emulatora klawiatury
#72840
Author: Adam Wysocki
Date: Wed, 11 Oct 2017 12:29
13 lines
1347 bytes
Tinta Tintoski <tintoski@gmail.com> wrote:

> 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.

W zmiennej w C, czy w zmiennej środowiskowej (np. bash)?

Pokaż dokładnie co wyświetla program.

-- 
[ Email: a@b a=grp b=chmurka.net ]
[ Web:   http://www.chmurka.net/ ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads