?
Solved

how to detect type device scanner or keyboard  ?

Posted on 2014-03-20
5
Medium Priority
?
890 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Bembi
Bembi earned 150 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 1350 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

762 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