4

I have two devices(KeyBoard and BarCodeScanner) and 2 textboxes(text box 1 and text box 2).

Now I want to restrict user that he can only use keyboard in text box 1 and barcodescanner in text box 2.

How is this possible in C#?

wonea
  • 4,783
  • 17
  • 86
  • 139
Zain Ali
  • 15,535
  • 14
  • 95
  • 108
  • possible duplicate of [How do I tell if keyboard input is coming from a barcode scanner?](http://stackoverflow.com/questions/5620745/how-do-i-tell-if-keyboard-input-is-coming-from-a-barcode-scanner) Once we figured out what this guy actually wanted, I think the edits I made to my answer ended up being pretty comprehensive. – Cody Gray - on strike Apr 25 '11 at 08:39

3 Answers3

2

You should have a look at this: Read data from Bar Code Scanner in .net (C#) windows application!

So your scanner might send special characters to help you identify it the input was from a scanner, or maybe it provides you with an additional library you could use to detect such events. Let's suppose thought the scanner acts identically to a keyboard without any special characters to help you know it was from a scanner and without any additional library from the manufacturer site you could use. Then what you could use is: measure the typing speed in the KeyDown event of the second textbox.

I suspect the scanner enters the code instantly so you would have a huge typing speed measured.

Then if the typing speed is greater than a threshold ( E.g. for humans the world speed record is somewhere around 1000 characters per minute) then you delete the text that was entered. It's hacky, but I've got no better idea.

Community
  • 1
  • 1
Liviu Trifoi
  • 2,980
  • 1
  • 21
  • 28
  • special character sequence will be different for every scanner so my application will become barcode model dependant.Can i generalize this any way? – Zain Ali Apr 27 '11 at 11:13
  • Not in a 100% reliable manner. The only idea that I have is to detect this by measuring when somebody enters characters at speeds greater than human typing speed like I described in the second part of my answer. But it's hacky. – Liviu Trifoi Apr 27 '11 at 13:18
1

It depends on how the scanner is connected I guess. If it's just wired in between the computer and the keyboard, you're out of luck, since there wouldn't be any reliable way to distinguish keyboard inputs from scanner inputs.

If it's connected separately there must be some means to get at the scanner data, maybe by way of a class that the scanner software provides, so you have to use what's provided there and put whatever you receive into TextBox2.Text. As for disabling the Keyboard input for this box, you could simply prevent any input by setting TextBox2.ReadOnly = true.

takrl
  • 6,356
  • 3
  • 60
  • 69
1

I worked with barcode scanner only once. In my scaner was possible to force it to generate special control sequence before it pass input to computer. This behavour was mastered through scanner's native software. But I cant specify any details because of I didnt participate in customizing - my colleague customized it before me .
In my case scanner sent Ctrl+J before scanned date and I was able to determin from which source input come from keyboard or from barcode scanner.

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69