【问题标题】:Is it possible to scan barcodes into a process in the background?是否可以在后台将条形码扫描到进程中?
【发布时间】:2017-05-07 18:06:47
【问题描述】:
我正在制作一个处理登录的健身房管理网络应用。会员的标签上有一个条形码,当他们到达健身房时会扫描该条形码。
我听说大多数条码扫描器只是充当键盘。这将需要在扫描条码时打开并在前台打开扫描页面。
如果它只是一个键盘,我如何将条形码扫描仪输入发送到计算机上运行的单个后台进程,并让它被所有可能处于焦点的进程忽略?
【问题讨论】:
标签:
io
device
background-process
barcode
barcode-scanner
【解决方案1】:
您说得对,大多数扫描仪都可以在键盘仿真中支持 HID,但这只是开始。
如果您想对数据进行更多控制,可以使用支持 OPOS 驱动程序模型的扫描仪。
查看Zebra's Windows SDK 以了解您可以执行的操作。这可能比尝试窃取操作系统中的条形码数据作为前台应用程序的键盘输入更好的解决方案。
免责声明:我为 Zebra Technologies 工作
其他条码扫描器供应商支持类似的驱动程序模型。
【解决方案2】:
我发现了一个有趣的帖子,里面有一个简单的解决方案:
关于表单构造函数
InitializeComponent():
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
处理程序和支持项目:
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();
}
}
致谢:@ltiong_sh
原帖:Here