react-native-keyevent
react-native-keyevent copied to clipboard
Event Handler Not Firing
I installed like:
yarn add react-native-keyevent
react-native link react-native-keyevent
In my code:
import KeyEvent from 'react-native-keyevent';
class MyComponent extends Component {
componentDidMount() {
KeyEvent.onKeyUpListener((keyCode) => {
console.log(`Key code pressed: ${keyCode}`);
});
}
render() {
// stuff including TextInputs
}
}
When pressing a key on the keyboard on an Android device or emulator, the event handler it not called.
This library only reads external keyboard events (like bluetooth connected keyboards). Are you using the on-screen phone keyboard?
I'm using the TV for up and down arrow buttons. It wont fire anything.
Does adb shell input text "hello" from the commandline count as an external event?
Hi guys, I'm having the same problem. I've linked the library manually and I'm using React Native 0.59.9. Expanding on my comment:
- Not using Expo
- Using an external keyboard connected via the charger port
Hey guys! Did you go through the configuration part? I was getting the same behaviour, but came back to the docs and realized that I forgot to go through this part.
Hope it helps :)
Another thing that I stumped on was that TextInputs was capturing the keyPresses before the listener, so it wasn't firing if focused on some input.
Hey guys! Did you go through the configuration part? I was getting the same behaviour, but came back to the docs and realized that I forgot to go through this part.
Hope it helps :)
You just saved my day! :smile: Totally overlooked the configuration part.