得到吧code读者价值形态后台监控 [英] get barcode reader value form background monitoring

查看:225
本文介绍了得到吧code读者价值形态后台监控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个C#语言的会计程序。 我想用一个吧code读卡器搜索产品店(这是可选的我的程序) 现在,在主窗体,如果卖家采用的是吧code读者获取处理方法或事件吧code值; 我怎样才能得到吧code表格的背景(没有文本框)的处理方法或事件的价值?

I want to create an accounting program with c# language. I want to use a barcode reader for searching products in shop (this is optional for my program) Now, in main form if seller uses a barcode reader get barcode value for handle method or event; How can I get barcode value in background of Form (without text box) for handle method or event ?

注:我的吧code读者HID(USB接口)

Note: My barcode reader is HID (USB interface)

推荐答案

酒吧code设备的行为就像一个键盘。当你有焦点的文本框,它发送字符的文本框,如果你从键盘键入他们。

The barcode device behaves like a keyboard. When you have focus in a textbox, it sends characters to the textbox as if you typed them from the keyboard.

如果你不想使用文本框,你需要订阅一个键盘事件处理程序来捕捉吧code流。

If you dont want to use a textbox, you'll need to subscribe to a keyboard event handler to capture the barcode stream.

Form1.InitializeComponent():

Form1.InitializeComponent():

this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);

&处理程序放大器;配套项目:

Handler & supporting items:

DateTime _lastKeystroke = new DateTime(0);
List<char> _barcode = new List<char>(10);

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    // check timing (keystrokes within 100 ms)
    TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
    if (elapsed.TotalMilliseconds > 100)
        _barcode.Clear();

    // record keystroke & timestamp
    _barcode.Add(e.KeyChar);
    _lastKeystroke = DateTime.Now;

    // process barcode
    if (e.KeyChar == 13 && _barcode.Count > 0) {
        string msg = new String(_barcode.ToArray());
        MessageBox.Show(msg);
        _barcode.Clear();
    }
}

您将不得不做跟踪的按键,并期待为回车,也就是发送瓦特/条code流。可以很容易地以阵列来完成。为了用户的击键和酒吧code按键一使坏,你所能做的就是保持按键的时机轨道区分。

You'll have to do keep track of the "keystrokes" and look out for the "carriage return" that is sent w/ the barcode stream. That can easily be done in an array. To differentiate between user keystrokes and barcode keystrokes, one dirty trick you can do is keep track of the timing of the keystrokes.

例如,如果你的击键小于100ms除了结束瓦特/回车流,你可以认为它是一间酒吧code和相应的过程。

For example, if you get a stream of keystrokes less than 100ms apart ending w/ a carriage return, you can assume it is a barcode and process accordingly.

另外,如果你的吧code扫描仪是可编程的,你也可以发送特殊字符或序列。

Alternatively, if your barcode scanner is programmable, you can also send special characters or sequences.

这篇关于得到吧code读者价值形态后台监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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