C # How to judge input of scanning gun and keyboard?

Source: Internet
Author: User

C # How to judge input of scanning gun and keyboard? In the receiving system, a scanner is often used to scan the bar code and input it to textbox. When the Bar Code cannot be scanned, you need to enter it manually. If the scanner is used for input, we will automatically interpret the bar code. When manually input the scanner, we need to press the Enter key to confirm and then interpret the bar code. At this time, we need to determine whether the input device is a manual or scanning gun.

Method:

1. Set the textbox attribute to readonly = true. Result: no input is allowed.

2. Set attribute E. Handle = true in the keypress event of textbox. Result: The keypress event is also triggered when the scanner is input. Therefore, the keypress event cannot be input.

3. Determine the result in the valuechanged event of textbox. Result: The scanner is also a single character input, instead of inputting the entire barcode at a time.

Thinking: The scanner is actually similar to the keyboard in terms of input. However, the difference between manual input and scanning device input is that scanning device input speed is faster and the interval is average.

Lab:

The inference from the experiment results.

Solution:

Private datetime _ dt = datetime. Now; // defines a member function to save each time point.
Private void textbox1_keypress (Object sender, keypresseventargs E)
{
Datetime tempdt = datetime. Now; // save the time when the key is pressed.
Timespan Ts = tempdt. Subtract (_ DT); // obtain the time interval
If (TS. milliseconds> 50) // determines the interval. If the interval is greater than 50 milliseconds, the textbox is cleared.
Textbox1.text = "";
Dt = tempdt;
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.