React Native 监听所有输入 [英] React Native listen all input
问题描述
首先,感谢您抽出时间阅读并提供帮助.
First, thank you for taking the time to read and help.
我们在 Android 设备上安装了第三方条码扫描仪.设备读取条形码并将数据作为键盘输入发回.我一直在寻找一种方法来捕获所有文本输入,但我一直无法找到全局文本输入侦听器.
We have a third party barcode scanner on an android device. The device reads the barcode and sends the data back as keyboard input. I have been looking for a way to just capture all text input, but I haven't been able to find a global text input listener.
有谁知道我可以在不强迫用户点击输入框的情况下执行此操作的方法(理想情况下我只会捕获而不将输入呈现给用户),然后扫描条形码?
Does anyone know a way I can do this without forcing the user to click into the input box (ideally I would just capture and never present the input to the user), and then scanning the barcode?
谢谢!
推荐答案
您想要的是捕获原始键盘事件.这与从外部 USB/蓝牙键盘获取输入相同.如果没有本机模块来捕获这些系统级事件,这将无法工作,这是正确的.
What you want is to capture the raw keyboard events. It's the same as getting input from an external usb/bluetooth keyboard. You are correct that this won't work without a native module to capture those system-level events.
这个 react native 库可以解决这个问题:https://github.com/kevinejohn/react-native-keyevent
This react native library can do the trick: https://github.com/kevinejohn/react-native-keyevent
这篇关于React Native 监听所有输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!