IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New C# - drain keyboard buffer
I've got an app that takes mag card swipes and barcode scans.

If a person gets "out of order", my QC logic will warn them and clear out the field. But if this is the result of an automatic scan, there still might be characters about to be sent to the field after I clear it out.

How do I drain the keyboard buffer?
New First thing I thought of
Check Console.KeyAvailable, use Console.ReadKey if there is one, loop until KeyAvailable returns false.

Jay
New Thanks
And now I realize I'm working on the 1.1 framework, yet I'm releasing on 2.x.
Ow well - some to upgrade.
New Do you control the barcode scanner?
Or is it fixed format?

I'm used to industrial (Code 39, Code 128), and I try to get the customer to always have a CR at the end of the scan (scanner is programmed to add CR at end). Most industrial scanners (and IIRC, some of the retail ones) will let you program start/end characters.

If it's a fixed format such as UPC/EAN, then you should know how many characters.

--Tony
New Yes
But I'm taking 2 mag swipes followed by a bar code on a production line.
Each field has a specific length that I stop at and validate the data (format, dupes, etc). I then jump to the next field.
After all three, I store into a database, log everything, clear out the fields, and prep for the next group.

The issue is when a person scans or swipes the wrong thing. Wrong length, bad validation, etc.

The goal is zero keyboard usage, but I can live with making them clear it out on error.
     C# - drain keyboard buffer - (crazy) - (4)
         First thing I thought of - (JayMehaffey) - (1)
             Thanks - (crazy)
         Do you control the barcode scanner? - (tonytib) - (1)
             Yes - (crazy)

I see... dead people.
49 ms