Hello, I am using Compact Framework for an Intermec CN3

I am watching a textbox's length and then automatically triggering an event when scanning a barcode (Using Code 128 barcodes)

private void txtBox_TextChanged(object sender, EventArgs e)
		{
			if (txtBox.Text.Length == 16)
			{
				DoMethod();
			}
			else
			{
				///Does nothing
			}
		}

The problem is, when a user manually enters in a 16 character code (If the barcode is unreadable) it will automatically trigger this event, I only want it to be automatically triggered when the scan button is pressed on the device. Unfortunately the way in which the device enters the string into the textbox is exactly the same as a user would enter it i.e. one character at a time. Can anyone see a logical way I could get around this?

Thank you

Perhaps you could implement the KeyDown event handler of the textbox to detect if the key was from the keyboard or from your scanning device?

So for instance, watch what characters are input within a range?

if (e.KeyChar >= 48 && e.KeyChar <= 57)
{
//Do nothing
}
else
//It must be using the scanner button

(I am aware that 47 to 57 isn't the entire range)

Yes, something like that, but I don't know how your scanner device does it. There must be some difference, like you can detect the difference between typing a number on the keypad and a number on the keyboard.

Hmm, this is proving to be tricky

I am using

if (e.KeyChar >= 0 && e.KeyChar <= 127)
			{
				MessageBox.Show("Keyboard");
				//Do nothing
			}

To try and differentiate keyboard input from scanned input but it actually still hits that If statement as if the barcode scanned is mimicking the button being pressed individually.

It will be tricky indeed, but is your scanner device not able to put up some sort of communication, like "He it's me I'm sending you some chars..."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.