C++控制台窗口仅从 USB 获取输入

发布于 2024-11-30 20:50:59 字数 450 浏览 2 评论 0原文

我不精通 C++,因此如果能很好地/详细地解释答案,我们将不胜感激,谢谢。 我制作了一个小型 C++ 程序,它从 RFID 读取器(类似于条形码扫描仪)获取输入。我尝试在互联网上搜索一个简单的答案,但得到了一些混合的结果。

我有两个选择,第一个是首选:

  1. 将控制台应用程序保留在后台(只需最小化即可)并从 USB RFID 读取器获取击键,并且仅从该源获取击键,以便 PC 上的用户可以使用他/她的键盘并在应用程序不处于焦点的情况下打开其他程序。

  2. 即使意外按下键盘或鼠标,也使应用程序保持焦点,因此即使单击任务栏,或者应用程序失去焦点,它也会重新获得焦点,以便继续执行其工作

我需要的答案不能只是“使用此功能” SetWindowFocus()”或“使用这个库和bla bla”,我需要一个关于我需要做什么的详细答案,因为我什至不知道从哪里开始,非常感谢您的帮助!

I am not profficient in C++ so answers explained well/in detail would be appreciated thank you.
I have made a small C++ program that takes the input from an RFID reader (Similar to a barcode scanner) I have tried searching all over the internet for a simple answer but have had some mixed results.

I have two options, the first is much preffered:

  1. Keep the console application in the background (just minimized is fine) and take keystrokes from the USB RFID reader, and ONLY from that source, so the user on the PC can use his/her keyboard and open other programs without the application being in focus.

  2. Keep the application in focus even if the keyboard or mouse is accidently pressed, so even if the taskbar is clicked, or the application loses focus it will regain focus so it can carry on doing it's job

The answer I need cannot just be "Use this function SetWindowFocus()" or "Use this library and bla bla", I need a detailed answer on exactly what I need to do, because I don't even know where to start, thank you very much for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坚持沉默 2024-12-07 20:50:59

RFID 读取器是否显示为 HID 键盘? Win32 原始输入 API 将允许您订阅特定键盘并将其输入与真实键盘区分开来。

首先阅读 http://www.toymaker.info/Games/html/raw_input.html< /a>

为此,除了控制台窗口之外,您的控制台应用程序还需要创建一个普通窗口(我认为它可以隐藏)。

听起来您确实需要一些有关 Win32 编程的教程。

由于您没有向我们提供任何详细信息(什么编译器,您使用的是 IDE,是否有您喜欢使用的特定框架库),我们很难给您具体的建议。但是,Raymond Chen 的博客“The Old New Thing”上有一些关于 Win32 窗口创建和消息处理的很好的介绍性文章。甚至还有一个完整的框架示例,您可以用它来启动自己的示例程序。

Does the RFID reader appear as an HID keyboard? The Win32 Raw Input API will allow you to subscribe to a particular keyboard and differentiate its input from the real keyboard.

Start by reading http://www.toymaker.info/Games/html/raw_input.html

To do this, your console application will need to create a normal window (I think it can be hidden) in addition to the console window.

It sounds like you really need some tutorials on Win32 programming.

Since you haven't given us any details (what compiler, are you using an IDE, is there a particular framework library you prefer to use) it's very difficult for us to give you specific advice. But there are some good introductory articles on Win32 window creation and message processing at Raymond Chen's blog "The Old New Thing". There's even a complete skeleton example you can use to start your own programs.

痴梦一场 2024-12-07 20:50:59

呃,始终保持专注,你真的做不到这一点。

请参阅此博文了解 Microsoft 采取的步骤在较新版本的 Windows 中采用,以避免应用程序窃取焦点并“始终位于最前面”。

我建议要么全屏显示,从而避免单击任务栏的可能性(但可以使用窗口按钮),要么深入输入设备以始终获取事件,无论用户在做什么。

这两种解决方案都不是完美的,但在 Windows 上,这就是规则。

W.r.t, always retaining focus, you can't really do that.

See this blog post about the steps Microsoft has taken in newer versions of windows to avoid applications stealing focus and being "always on top".

I suggest either going fullscreen, thus avoiding the possibilty to click the taskbar (but one could use the windows button), or, hooking deep into the input device to always get events, no matter what the user is doing.

Neither solution is neat, but on Windows, that's the rules.

无戏配角 2024-12-07 20:50:59

我也有同样的问题。我搜索并尝试了很多东西。

使用 hidapi 例如 RFID 显示信息,但我无法读取数据。
C++ 程序可以工作,但 RFID 读取器到处都写入十六进制数字。也许每个人都有一些代码来将阅读器初始化到我的程序中。

I had the same problem. I searched and tried many things.

With hidapi e.g. the RFID show info, but I couldn't read data.
The C++ program works but the RFID reader write hex number everywhere. Maybe everyone have some code to initialize the reader into my program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文