Solved

how to detect type device scanner or keyboard  ?

Posted on 2014-03-20
5
538 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
Comment Utility
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
Comment Utility
ok but how to make it by c#
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now