Played briefly with barcodes yesterday –
There was a usb barcode scanner lying around MITERS which Michael handed me, you plug it in and it behaves like a keyboard.
See video, which demonstrates scanning what I was hoping would be a backspace (but is actually reading as Ctrl-H), and then scanning a normal barcode on a box lying around.
Anyway, so of course we have the terrible idea of a barcode keyboard, which given that I need to urgently work toward my quals exam at the end of January, seemed like a perfect thing to waste time on (short brainless self-contained project). Of course after the first step I made it more convoluted and worked on it for several hours… but anyway.
I present: The barcode keyboard! 😄
Video of it in action here, starring expert scanner Mike:
And the source files:
The barcodes were generated using a website: https://barcode.tec-it.com/en/Code128? (Note that can only create five at a time).
That’s it! I should’ve stopped there! But…
Well I noticed that my backspace barcode key doesn’t work :’( Despite checking “evaluate escape expression” on the barcode generator.
After some debugging (detailed below) I realized that my computer thinks I’m presseing “Ctrl-H” (^H) which is what used to be backspace presumably on some ancient terminal system.
Page 17 (shown on left side of screenshot) lists the codes: https://www.tec-it.com/download/PDF/Barcode_Reference_EN.pdf
So, getting a backspace working is for future work.
Of course, along the way as I was looking at ASCII tables, I realized there are some extended ASCII codes that look kinda like I might be able to piece together some of the emoji (? unicode art ish?) online. Specifically, I wanted to be able to scan a barcode and get out
So the ASCII equivalents aren’t a perfect match, but the closest I got was:
\250_\250 ) ( \250_\250 ) > \218\254-\254 ( \218\254_\254)
And I stuck the outputs into a word editor to get
But when I went to scan it, I only got out
_ ) ( _ ) > - ( _) _ ) _ )
So, getting special things is left for future steps. But it’s neat to know that I can do weird things like Ctrl-H just from scanning a barcode.
The rest of the blog post will mostly be notes from my debugging process.
To get closer to what the barcode scanner was “actually” outputting and to compare it to the difference from me pressing the key, I looked at
Xev and Xinput
$ dmesg | tail [340287.860812] usb 3-2: new full-speed USB device number 6 using xhci_hcd [340293.199985] usb 3-2: New USB device found, idVendor=05e0, idProduct=1200, bcdDevice= 2.01 [340293.199989] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [340293.199993] usb 3-2: Product: Symbol Bar Code Scanner [340293.199995] usb 3-2: Manufacturer: ﾩSymbol Technologies, Inc, 2002 [340293.199997] usb 3-2: SerialNumber: S/N:F37202D96BE67D41B4B4CF7B41E2A6B8 Rev:NBRMIAAS3 [340293.203189] input: ﾩSymbol Technologies, Inc, 2002 Symbol Bar Code Scanner as /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/0003:05E0:1200.0007/input/input24 [340293.265599] hid-generic 0003:05E0:1200.0007: input,hidraw0: USB HID v1.10 Keyboard [ﾩSymbol Technologies, Inc, 2002 Symbol Bar Code Scanner] on usb-0000:00:14.0-2/input0
chai@W530:/dev$ $ xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)] ⎜ ↳ TPPS/2 IBM TrackPoint id=13 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master keyboard (2)] ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] ↳ Power Button id=6 [slave keyboard (3)] ↳ Video Bus id=7 [slave keyboard (3)] ↳ Video Bus id=8 [slave keyboard (3)] ↳ Sleep Button id=9 [slave keyboard (3)] ↳ Integrated Camera: Integrated C id=10 [slave keyboard (3)] ↳ AT Translated Set 2 keyboard id=11 [slave keyboard (3)] ↳ ThinkPad Extra Buttons id=14 [slave keyboard (3)] ↳ ﾩSymbol Technologies, Inc, 2002 Symbol Bar Code Scanner id=15 [slave keyboard (3)] chai@W530:/dev$ $ xinput test 15 chai@W530:/dev$ $ xev
The “q” key:
$ xev KeyPress event, serial 37, synthetic NO, window 0x5200001, root 0x181, subw 0x0, time 341559163, (55,-13), root:(1347,511), state 0x0, keycode 24 (keysym 0x71, q), same_screen YES, XLookupString gives 1 bytes: (71) "q" XmbLookupString gives 1 bytes: (71) "q" XFilterEvent returns: False $ xinput test 11 key press 24 key release 24
Wow. Much confusion —
What are all these numbers?
“Q” is 81 there because it is ASCII 81 (in decimal). But why is it 24 in xinput, and 71 in xev??
E.g. backspace key
In xinput list,
key press 22 key release 22
KeyRelease event, serial 37, synthetic NO, window 0x4400001, root 0x181, subw 0x0, time 347196546, (114,-9), root:(1504,380), state 0x0, keycode 22 (keysym 0xff08, BackSpace), same_screen YES, XLookupString gives 1 bytes: (08) " XFilterEvent returns: False
But also these ways??
\8 \b ^H
The last is the issue – gets interpreted as Ctrl-H.
Looking around I didn’t see much to help me.
There are a lot of players between your keyboard and the process that finally handles the keyboard event. Among the major pieces of the landscape are the fact that the X system has its own keyboard-handling layer, and X associates different “keycodes” with keys than your Linux base system does. The showkey command is showing you the keycodes in Linux-base-system lingo. For xmodmap you need the X keycodes, which are what xev is displaying. So long as you’re planning to work in X and do your key rebinding with xmodmap, then, ignore showkeys and just listen to what xev says.
Of course, being able to scan a barcode and hit “ctrl-h” makes one wonder… can you make malicious barcodes? Turns out someone on the intenret has looked into this: http://www.irongeek.com/xss-sql-injection-fuzzing-barcode-generator.php
- Get another barcode scanner, dual wielding! Play Doom or something with barcode scanners XD
- Get backspace working. The second barcode scanner, hopefully from different manufacturer, can help tell me if it’s something weird about this particular scanner such that it’s outputting Crl-H instead of backspace.
- Get sunglasses emoji barcode working
- Understand more about the barcode systems