Disable input from keyboard and allow Barcode reader only using Java [closed]

杀马特。学长 韩版系。学妹 提交于 2020-01-25 19:20:49

问题


How can you disable input from keyboard and restrict to a barcode reader using only Java?


回答1:


Unfortunately, I don't think this is possible, at least not by using "only Java".

Most barcode readers I've seen look just like a keyboard to the computer. If you're using a barcode reader that doesn't operate "as a keyboard", and can be used with the Java Communications API, then you have some additional options here. Otherwise, I'm assuming that you're using keyboard-type scanners for the rest of this answer.

If not within some software written to read the barcode reader output, I could open up Notepad, place the cursor within the window, scan the barcode, and the #'s will appear just as if I had typed them in manually.

In order to determine that the entered characters came from the barcode reader rather than the keyboard, you'd need to interface at a lower-level with the OS to determine which input device was used. As far as I know, Java doesn't provide any API for this. You'd need to investigate using JNI, which would then have to be written and maintained per supported operating system.

The other possibility is that some scanners will generate special header data as part of the scan. This may be configured into the scanner, or may be part of the barcode itself. In either case, a keyboard listener could be registered to listen for this data, then handle it appropriately. Unfortunately, this doesn't work well from a security perspective, because this means that there are other ways to repeat the input of this data without actually scanning the barcode. (For that matter, if security is a concern, barcodes are the wrong approach - as barcodes can easily be copied or generated.)



来源:https://stackoverflow.com/questions/8229513/disable-input-from-keyboard-and-allow-barcode-reader-only-using-java

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