VUE.JS条形码扫描仪生产“键盘”仅当用户在输入框上时。当用户不在输入框上时要收听什么事件?

发布于 2025-02-12 23:31:19 字数 356 浏览 0 评论 0原文

我使用手动条形码扫描仪的工作,

我希望有可能在没有输入框的情况下捕获扫描事件,除了我在哪里,并扫描我可以听的代码并执行所需的操作。

我尝试在已安装和创建的功能中使用以下代码,但没有打印控制台。log:

window.addEventListener ('keypress', function (e) {
   console.log ('window scanner barcode');
})

document.addEventListener ('keypress', function (e) {
  console.log ('document scanner barcode');
})

谢谢

I work with a manual barcode scanner

I want the possibility of capturing the scan event without a input box, except that wherever I am and scan the code I can listen to it and do the required action.

I tried using the following code in the mounted and created functions but did not print the console.log:

window.addEventListener ('keypress', function (e) {
   console.log ('window scanner barcode');
})

document.addEventListener ('keypress', function (e) {
  console.log ('document scanner barcode');
})

Thank you

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

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

发布评论

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

评论(1

花开雨落又逢春i 2025-02-19 23:31:19

我一直在研究和实验。需要考虑的几件事:

  • 扫描仪只是在键盘事件上转发。有些扫描仪执行键盘而不是按键。 键盘事件的实验或联系技术支持
  • 无论您的扫描仪是否专注
  • (我认为大多数扫描仪), 确实会被解雇。因此,扫描的“ 123”之类的字符串会触发3键:'1','2','3'。

基于此,您必须在JavaScript中创建适当的逻辑来处理扫描仪输入。

I've been researching and experimenting. A few things to consider:

  • Scanners simply forward on keyboard events. Some scanners do keydown instead of keypress. Either experiment or contact technical support for your scanner
  • The keyboard event does indeed get fired whether an input is focused or not
  • My scanner (and I would assume most scanners), will enter each character that is scanned one character at a time. Therefore a string like '123' that is scanned would trigger 3 keypresses: '1', '2', '3'.

Based on this, it's up to you to create the proper logic in your javascript to handle the scanner input.

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