在文本框中输入时,如何获取在 react-native 应用程序中按下了哪个键?
How to get which key was pressed in react-native app, while take input in text box?
我一直在尝试制作用户按下 "enter" 时的输入芯片。我怎样才能在本机反应环境中实现这一目标?我正在尝试使用 "onKeyPress" 事件但未提供解决方案。
这是我的代码:
<Input style={formCSS.textFieldInput} onKeyPress={(keyPress) => console.log(keyPress)} placeholder='Hobbies' />
期望结果的图片
根据文档,onKeyPress
Callback that is called when a key is pressed. This will be called
with { nativeEvent: { key: keyValue } } where keyValue is 'Enter' or
'Backspace' for respective keys and the typed-in character otherwise
including ' ' for space. Fires before onChange callbacks. Note: on
Android only the inputs from soft keyboard are handled, not the
hardware keyboard inputs.
所以你应该像这样使用它
onKeyPress={(e) => console.log(e.nativeEvent.key)}
我一直在尝试制作用户按下 "enter" 时的输入芯片。我怎样才能在本机反应环境中实现这一目标?我正在尝试使用 "onKeyPress" 事件但未提供解决方案。
这是我的代码:
<Input style={formCSS.textFieldInput} onKeyPress={(keyPress) => console.log(keyPress)} placeholder='Hobbies' />
期望结果的图片
根据文档,onKeyPress
Callback that is called when a key is pressed. This will be called with { nativeEvent: { key: keyValue } } where keyValue is 'Enter' or 'Backspace' for respective keys and the typed-in character otherwise including ' ' for space. Fires before onChange callbacks. Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.
所以你应该像这样使用它
onKeyPress={(e) => console.log(e.nativeEvent.key)}