Search code examples
clinuxkeyboardusbbarcode-scanner

Linux, reading from barcode scanner


I have barcode scanner, attached to Linux computer via USB. The scanner emulates a keyboard device.

I have to write a program that to read the scanned barcodes and process them. The program runs on background as a service and should read the barcode scanner regardless of the current X focus.

How this can be made in Linux?

Some lower level solution/explanation is preferred.


Solution

  • It sounds like you want to capture the data from a specified device, In which case the method described in this post should help:

    (EDIT: original link dead, Archive link provided)

    https://web.archive.org/web/20190101053530/http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/

    That will listen out for keyboard events stemming from only the specified source.

    A word of caution though, as far as I know, that won't stop it from propagating to whatever your current window focus is.