我如何判断键盘输入是从酒吧code扫描仪来了吗? [英] How do I tell if keyboard input is coming from a barcode scanner?

查看:165
本文介绍了我如何判断键盘输入是从酒吧code扫描仪来了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一台计算机上我同时拥有普通键盘和酒吧code扫描仪可模拟键盘。当我的应用程序获取键盘输入,我怎么能确定是否该输入是在酒吧code扫描仪或真正的键盘来了吗?

On one computer I have both a regular keyboard and a barcode scanner which emulates a keyboard. When my app gets keyboard input, how can I determine whether that input is coming from the barcode scanner or the real keyboard?

推荐答案

您会得到两个输入。不是的同时的,当然。这都将被放入队列中,但Windows将处理来自键盘的按键事件。

You'll get input from both. Not simultaneously, of course. It will all be placed into a queue, but Windows will process key events from both keyboards.

不要无奈,虽然。正如大卫·赫弗南建议,你可以很容易地通过插入两个键盘到电脑上,打开了记事本,并键入随机字符,看看哪一个产生输入摸不着头脑吧。

Don't be helpless, though. As David Heffernan suggests, you can easily figure this out yourself by plugging in both keyboards to your computer, opening up Notepad, and typing random characters to see which one generates input.

您的答复是,要检查用C#code,但我不知道这意味着什么。如何创建一个控制台应用程序,从键盘读取输入,并在屏幕上显示出来?

You reply that you want to "check that with C# code", but I have no idea what that means. How about creating a console app that reads input from the keyboard and displays it on the screen?

using System;

class AdvancedKeyboardTester
{
   static void Main(string[] args)
   {
      for (; ;)
      {
         Console.ReadKey();
      }
   }
}

preSS <大骨节病>控制 + <大骨节病> C 当你的乐趣轮胎,想退出程序。

Press Ctrl+C when you tire of the fun and want to quit the program.

编辑:这听起来像你正在寻找的 RegisterRawInputDevices 功能,它允许您启用原始输入您所有的键盘,然后枚举的结果,以确定哪个设备发送的消息。

It sounds like you're looking for the RegisterRawInputDevices function, which allows you to enable raw input for all of your keyboards, and then enumerate through the results to determine which device sent the message.

幸运的是,它看起来像有人已经写了一个C#包装库本,可供下载code项目:的使用原始输入从C#来处理多个键盘

Fortunately, it looks like someone has already written a C# wrapper library for this, available for download on Code Project: Using Raw Input from C# to handle multiple keyboards

编辑2:(看来信息只是不断从注释欺骗中)

Edit 2: (it seems the information just keeps tricking in from the comments)

如果您使用的是吧code扫描仪,这变得轻松了许多。因为他们明确地为此而设计的,他们几乎所有的可编程的。这意味着你可以告诉他们,以preFIX(和/或后缀)他们的意见与指示输入与酒吧code扫描仪来了,而不是一个标准键盘部分的定点字符。 (检查你的吧code扫描仪的用户手册,了解更多信息。)然后,所有你需要做的就是筛选出基于这些定点字符presence与否的键盘输入。你也可以检查如何迅速的preFIX和后缀的字符输入了。

If you're using a barcode scanner, this gets a lot easier. Because they're explicitly designed for this purpose, they're almost all programmable. Meaning that you can tell them to prefix (and/or suffix) their input with some sentinel characters that indicate the input is coming from the barcode scanner, rather than a standard keyboard. (Check your barcode scanner's user manual for more information.) Then, all you have to do is filter out the keyboard input based on the presence or absence of those sentinel characters. You can also check for how quickly the characters between the prefix and suffix were entered.

这篇关于我如何判断键盘输入是从酒吧code扫描仪来了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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