3

I just started working with Ubuntu/Linux so my knowledge is limited. My idea was to use a barcode scanner in my c++ program as an input device. This works perfect when it comes to reading. I just open the file which represents my barcode scanner and with the input_event struct I can read in a loop the input like this:

int connection = open("dev/input/by-id/my-barcode-scanner", O_RDONLY);

the scanner acts like a keyboard

struct input_event ie[64];
int rd, value, size = sizeof(struct input_event);

while ((rd = read(serialPort, ie, size * 64)) > size) {
    std::cout << "The entered code is: " << ie[1].code << std::endl;        
}

This is of course very simplified. I have different sequences that trigger different actions. This part works just fine. My problem is that not only my program gets the input, also the focused UI. I would like to consume the input of this device, so it is not shown anywhere else. I am used to very "high level" events of Java, where you can simply consume an event or pass it through. So I am very curious if there is something I can do on this very low level to "consume" it. I tried already read and overwrite the content and to change the group of the /dev/input/event file, I thought maybe if it is not in the input group it would not use it, but apparently it is not as easy than that. Looking forward for ideas or anything which makes me understand better.

0

1 Answer 1

1

You should probably be using libevdev to read events, and then using grab which can stop events being distributed to others.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .