componentDidMount() {
KeyEvent.onKeyDownListener((keyEvent) => {
if (keyEvent.keyCode === 'Keycode of the power button'){
this.timeout = setTimeout(() => {
//Your SOS Function here
}, 1000)
}
});
KeyEvent.onKeyUpListener((keyEvent) => {
if (keyEvent.keyCode === 'Keycode of the power button'){
clearTimeout(this.timeout)
}
})
}
componentWillUnmount() {
KeyEvent.removeKeyDownListener();
KeyEvent.removeKeyUpListener();
}
2条答案
按热度按时间z9zf31ra1#
您可以使用react native的react-native-keyevent包。
ecfdbz9o2#
只是只有键码电源不显示日志事件时,IAM按下,任何解决方案?