How to read and consume the input of /dev/input/
3
votes
1
answer
4439
views
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;
int rd, value, size = sizeof(struct input_event);
while ((rd = read(serialPort, ie, size * 64)) > size) {
std::cout << "The entered code is: " << ie.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.
Asked by user2267367
(131 rep)
Aug 27, 2021, 07:43 AM
Last activity: Dec 13, 2023, 01:11 AM
Last activity: Dec 13, 2023, 01:11 AM