禁用键盘输入,仅允许使用Java的条形码阅读器 [英] Disable input from keyboard and allow Barcode reader only using Java

查看:111
本文介绍了禁用键盘输入,仅允许使用Java的条形码阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅使用Java禁用键盘输入并限制为条形码阅读器?

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

推荐答案

不幸的是,我认为这是不可能的,至少不能通过使用仅Java"实现.

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.

为了确定输入的字符来自条形码读取器而不是键盘,您需要与操作系统进行较低级别的连接才能确定使用了哪个输入设备.据我所知,Java没有为此提供任何API.您需要使用JNI进行调查,然后必须根据受支持的操作系统编写和维护JNI.

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.)

这篇关于禁用键盘输入,仅允许使用Java的条形码阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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