Since the scanner is and must be configured as a USB keyboard, I am forced to capture the input using a low level keyboard hook. However, instead of using STX/ETX characters as prefix/suffix, I have now set up the scanner to send a keyboard command (Alt + Shift + Backspace) as prefix and suffix.
This allows me to determine when a barcode is coming and when it has finished. To prevent users from accidentally (or intentionally) oerforming the keyboard command I have implemented a timer. The timer makes sure that barcode parsing is cancelled if no barcode is received after 100 milliseconds.
The keyboard command is caught using the RegisterHotKey and UnregisterHotKey Windows API calls.
When swallowing input during barcode processing it is very important not to swallow the backspace character. The low level keyboard hook is called prior to the hot key callback and swallowing the backspace character will prevent the hot key callback from ever occuring.