@linvix-sistemas/react-native-keyevent-android
Pacote para detectar as teclas pressionadas no teclado no android.
Instalação
npm install @linvix-sistemas/react-native-keyevent-android
yarn add @linvix-sistemas/react-native-keyevent-android
Configuração
Adicione/mescle as seguintes linhas no arquivo: MainActivity.java
import android.view.KeyEvent;
import com.reactnativekeyeventandroid.KeyEventModule;
public class MainActivity extends ReactActivity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
KeyEventModule.getInstance().onKeyDownEvent(keyCode, event);
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
KeyEventModule.getInstance().onKeyUpEvent(keyCode, event);
return super.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
KeyEventModule.getInstance().onKeyMultipleEvent(keyCode, repeatCount, event);
return super.onKeyMultiple(keyCode, repeatCount, event);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
KeyEventModule.getInstance().onDispatchKeyEvent(event);
return super.dispatchKeyEvent(event);
}
......
}
Uso
import KeyEventAndroid from '@linvix-sistemas/react-native-keyevent-android';
useEffect(()=> {
const CleanListenerKeyDown = KeyEventAndroid.onKeyDownListener((ev) => {
console.log(`KeyCode: ${ev.keyCode}`);
console.log(`Action: ${ev.action}`);
console.log(`Key: ${ev.pressedKey}`);
console.log(`Enter?: ${ev.enterPressed}`);
});
const CleanListenerKeyUp = KeyEventAndroid.onKeyUpListener((ev) => {
console.log(`KeyCode: ${ev.keyCode}`);
console.log(`Action: ${ev.action}`);
console.log(`Key: ${ev.pressedKey}`);
console.log(`Enter?: ${ev.enterPressed}`);
});
const CleanListenerKeyMultiple = KeyEventAndroid.onKeyMultipleListener((ev) => {
console.log(`KeyCode: ${ev.keyCode}`);
console.log(`Action: ${ev.action}`);
console.log(`Characters: ${ev.characters}`);
});
const CleanListenerDispatchKey = KeyEventAndroid.onDispatchKeyListener((ev) => {
console.log(`KeyCode: ${ev.keyCode}`);
console.log(`Action: ${ev.action}`);
console.log(`Characters: ${ev.characters}`);
});
return ()=> {
CleanListenerKeyDown();
CleanListenerKeyUp();
CleanListenerKeyMultiple();
CleanListenerDispatchKey();
}
}, []);
Contribuindo
Fique a vontade para fazer contribuições no projeto, ele é um projeto que a Linvix Sistemas está utilizando em seus projetos e achou conveniente disponibilizar para a comunidade.
License
MIT