在C#中使用条形码扫描仪 [英] using Barcode Scanner in c#

查看:224
本文介绍了在C#中使用条形码扫描仪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用条形码阅读器读取条形码,它只是返回文本.
条形码阅读器在Windows中被解释为HID,
我正在使用c#应用程序读取值..无论文本框是否具有焦点,我都必须在条形码扫描仪返回的文本框中捕获值.您能建议怎么做吗?
我也正在使用TextChanged事件,尽管这会造成问题,但是当文本框接收到输入时,事件会为输入中的每个字符触发,我如何才能首先接收整个输入然后触发一个事件?

我希望应用程序是完全自动化的,所以我不使用Click事件或按钮来执行其余操作...

谢谢.
Prathamesh

Hi,
I am using Barcode reader to read a barcode, it simply returns the text.
Barcode reader is interpreted as HID in windows,
I am using c# application to read the value.. I have to capture the value in a text box returned by Barcode scanner whether Textbox is having Focus or not.. Can you suggest how can it be done??
Also I am using TextChanged event which although is creating problem, when textbox recieves the input, event fires for each character in input,how can i first recieve whole input and then fire an event??

I want the application totally automatic so i am not using Click events or buttons to execute remaining operations...

Thanks.
Prathamesh

推荐答案

Am我理解条形码扫描器的作用就像第二个键盘一样,实际上是在键入"条形码的值吗?您/您如何区分键盘输入和扫描仪输入?

下一个问题是您使用WPF还是WinForms?如果是后者,听起来就像您想在窗体级别上尽早拦截按键.还有其他可以接受键盘输入的控件吗?

您可以使用类似这样的方法来捕获表单级别的所有击键:

Am I correct in understanding the barcode scanner acts like a second keyboard, in effect ''typing'' the value of the barcode? How do you/do you need to distinguish between input on the keyboard and input from the scanner?

Next question is are you in WPF or WinForms? If its the latter, sounds like you want to intercept the keystrokes early on, at a form level. Are there other controls which accept keyboard input?

You can use something like this to capture all keystrokes at form level:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (msg.Msg == 0x100)
    {
        // add to the string here
    }
    return base.ProcessCmdKey(ref msg, keyData);
}


我使用Mike O''Brien的HID库
https://github.com/mikeobrien/HidLibrary [
I use Mike O''Brien''s HID Library
https://github.com/mikeobrien/HidLibrary[^]

This will allow you to capture the data from your barcode reader and process it in a class or on a form.

Most USB barcode readers default to the keyboard wedge and if the device supports HID then there is a programming barcode to change the device to use HID. If the device doesn''t support HID then you are stuck with keyboard mode (or whatever mode it supports).


默认情况下,条形码扫描仪充当人工输入设备,您已经注意到和你一起这使他们可以直接使用"许多/大多数应用程序.

但是,它们中的许多可配置为提供特定的导入/导出代码,以允许它们以其他方式工作.如果要启用此功能,则必须与制造商联系,因为制造商和制造商之间可能会有所不同-可能会因模型而异.
Barcode scanner by default act as a human input device, as you have noticed with yours. This allows them to work "straight out of the box" with many / most applications.

However, many of them are configurable to provide specific lead in / lead out codes to allow them to work in other ways. You will have to speak to the manufacturers if you want to enable this, as it will vary from manufacture to manufacturer - and possibly model to model.


这篇关于在C#中使用条形码扫描仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆