How HID devices work when programming?

北城以北 提交于 2021-02-18 08:19:49

问题


I have a barcode scanner works as HID device. Everytime a barcode scans it goes directly to windows keyboard, for example if I open notepad I can see the barcode typed there.

As far as I know programmatically is it possible to to read HID data from your HID devices.

But what happens if the user is already on a form with a text edit control? The scanned code will go inside the text box.

Can you block incoming text and make a background-only processing?

Can you explain the theory please?


回答1:


See if your barcode scanner can emulate a serial port and just read the data directly from the the serial port into your app.

That is cleaner and less expensive then a global keyboard hook. When I was looking into this awhile ago I found that most USB barcode scanners can emulate a serial port, it's a cinch to read serial port data in most programming languages. I happened to be doing mine in Java, I posted an example in answer to this question actually.




回答2:


You can set up your scanner to use USB-HID(POS) setting. Your datasheet of barcode settings for the scanner device should have it. I use this project to test my scanners. http://www.codeproject.com/Articles/18099/A-USB-HID-Component-for-C




回答3:


Sure, just capture keypresses before they are handled by the control and suppress normal handling of the events. In VB.NET you might override the OnKeyPress method in your form and set KeyPreview to true, for example.



来源:https://stackoverflow.com/questions/10879808/how-hid-devices-work-when-programming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!