Solved

how to detect type device scanner or keyboard  ?

Posted on 2014-03-20
5
588 Views
Last Modified: 2014-04-10
hi
i want design form these form accept number for symbols scanners barcode only   if any one   type from normal keyboard  or copy past number not accept
how to detect type device scanner or keyboard  ?
  form
0
Comment
Question by:mahmuod
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Bembi
Bembi earned 50 total points
ID: 39943758
Every device has a HardwareID, if you search your registry for HardwareID you will find all of the installed devices. The HardwareID contains the vendor, a device type as well as a unique identification of the device itself. So You form has to indentify the HardwareID of the input device to decide, if it is allowed or not.

In the internet your find databases to identify a device by its hardwareID
0
 

Author Comment

by:mahmuod
ID: 39943821
ok but how to make it by c#
0
 
LVL 40
ID: 39949667
Check the events that are triggered when the scanner sends it information to the application. This can change depending on the scanner.

If the scanner sends only a KeyPress or a TextChanged and no KeyDown, then simply set e.SuppressKeyPress=True in the KeyDown event of the control. This will prevent a key from the keyboard from going to the control.

If this does not work with you scanner, you might want to use a timer to calculate the time it takes to type fill the control. Manual entry is usually a lot slower than the scanner, so with some tests, you should be able to come with a duration that will tell you if the scanner or the keyboard is sending the data. If the timing between the first character and the second one is too long, delete the first character and display a warning message.
0
 

Author Comment

by:mahmuod
ID: 39952526
The scanner action same keyboard . Can not select  type keyboard or scanner
But if the code only one deget can not calculate time
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 450 total points
ID: 39953344
Yes, you can calculate time with one digit.

Define a DateTime variable called lastTime at the Form level and use the following code in your KeyPress event:

		private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (lastTime>new DateTime()) // Do not react to the first character
			{
				if (DateTime.Now.Subtract(lastTime).Milliseconds>50)
				{ // This is the user typing }
				else
				{ // This is the scanner }	
			}
			lastTime = DateTime.Now; // Initialize the timer for the first character
		}

Open in new window


I have set the trigger delay to 50 milliseconds because this is the fastest speed at which I can type when go on like crazy on the keyboard. If your scanner is faster than that, that should be OK. Otherwise, you may try to increment the value, since a normal person that types as it reads the code will be a lot slower. 100 milliseconds per character seems to be proper for a fast typist.

If the form is used to make repeated reads, be sure to reset lastTime to new DateTime() when a reading is complete, to reinitialize the whole thing for the next reading.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sccm importing drivers 4 28
extended monitor print screen 8 33
Scheduled Tasks Tweak 5 31
Problem to Alipay 10 22
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question