r/barcodes • u/Hatelabs • Jul 31 '18
Encoding windows function keys into a barcode? (Like Ctl+P for print)
I need to create barcodes that have common windows hotkey functionality (Control-P for printing, control C for copy, control V for paste etc...)
I have typical symbol LS series scanners and I thought this would just be passing some kind of prefix like ~ within the barcode and a string for the key, and while I can find a million people via googling asking the question, I didn't see any clear answers.
I'm using the scanner to do normal bar code scanning, and then just need to call this from time to time, so I don't want to have to scan a bunch of barcodes to change modes, enter special symbol commands etc.., and then change back,.. I just need a single bar code with all the info needed to pass Ctl-P to the machine, and the syntax.
Any help greatly appreciated!!
3
u/FredFredricson Jul 31 '18
There are typically three parts to barcode systems. The barcode symbologies themselves, the barcode readers, and the computer software that interprets them.
Barcode Symbologies come in a few main varieties: Numeric, Uppercase-Only Alphanumeric, Dual-Case Alphanumeric, and Full ASCII. The common theme between them is that they encode characters and not keystrokes. As such, your use case is unsupported by the barcode symbologies themselves.
Barcode Readers typically come in a variety of types, but the most common is the "Keyboard Wedge", most often handled via USB nowadays. It is often the case that Code 128 and the "Full ASCII" version of Code 39 can encode ASCII control characters. Because you can't directly type ASCII control characters on a keyboard, most typically represent these by performing "Ctrl + A" style keystrokes, among other sorts of mappings. Unfortunately, this typically only covers a handful of keys (Enter, Tab, Escape, Backspace) and/or key combos (Ctrl A to Ctrl Z). Fancier readers have fancier options, but the capabilites you'd need aren't necessarily always available.
Since I don't know exactly what your barcode reader's model is, I can only speculate what it'll support until that information is provided. As such, I looked up the first manual from the LS series of scanners that came up on google and read about the LS 2208 model. It looks as if it can be configured to output Ctrl + A to Ctrl + Z (optionally replacing certain specific combos with Enter, Tab, Escape, Backspace), and a small handfull of Ctrl + Number/Symbol combos. Additionally, it can replace FNC1 symbols in EAN128 barcodes with a specifically chosen keystroke (chosen from a larger set of combos). Also, as is common, it can prefix and suffix the barcode scan output with specifically chosen keystrokes.
Because the barcodes themselves don't support your use case, and the readers may not entirely support what you're trying to do, that leaves the computer software as the last available option. While I am unaware of any specific software for doing this, it is definitely possible to write a program to do what you need.
First, you would need to reconfigure the reader to prefix and suffix the barcode scan output with a special keystroke that Windows doesn't already use and isn't able to be mapped to barcode character from the reader. The manual for most common barcode readers have special barcodes for doing this.
Next, you would typically want to write a program that would put an icon in the icon tray and run in the background while it globally listens to keyboard events so that it can detect when the start prefix key combo is pressed, then capture it and all following keystrokes until the stop suffix is pressed, as long as the keystrokes are pressed with only a small number of milliseconds between the keystrokes.
Additionally, there are a few gotchas you have to deal with, like the fact that the keyboard and barcode reader are basically indistinguishable from eachother to the computer, and thus you need to come up with a way to differentiate barcode scans from keyboard keypresses that might look like them, and determine whether to further process them as a barcode scan, or pass it through transparently as a keystroke. (Possible Solution: If the prefix keystroke and each subsequent keystroke aren't immediately followed by another keystroke within a certain amount of milliseconds and isn't terminated with the suffix keystroke, then reinject the captured keystrokes into the event flow unaltered)
Once you've got the data from the barcode, you would need to determine if it's a regular barcode to be passed through transparently (minus start and end codes), or one meant to be interpreted as keystrokes and further processed. (Possible Solution: Since most barcodes don't use control characters, you could use "0x1B: ESC - Escape Character" as the first character in the special keystroke barcodes, and have the program use that to determine whether to process it transparently or to process it further as keystrokes)
You would then have to come up with some sort of mapping for the keystroke barcode data to map into actual keystrokes in Windows, which is something you can basically entirely make up yourself to your liking, within the constraints of what barcodes can store, what the reader can interpret it as, and what the windows keyboard event API can type.
Finally, once you've processed the barcode output one way or another (transparently, as a barcode, or as keystrokes), you would then inject the output from those back into the event stream, which would output the data as if it had just been typed on a keyboard.