How to monitor the key events of the virtual keyboard, including the keycode. RawKeyboardListener has no effect on virtual keyboard keys.
void _onkeyclick(RawKeyEvent event) {
if (event is RawKeyDownEvent) {
if (event.data is RawKeyEventDataAndroid) {
RawKeyDownEvent rawKeyDownEvent = event;
RawKeyEventDataAndroid rawKeyEventDataAndroid = rawKeyDownEvent.data;
print(rawKeyEventDataAndroid.keyCode);
switch (rawKeyEventDataAndroid.keyCode) {
case 66:
}
}
}
}
Widget getItem(Pbtem pb) {
if (pb.type == 1) {
TextEditingController _c = new TextEditingController();
return new RawKeyboardListener(
focusNode: _focusNode,
onKey: _onkeyclick,
child: new EditableText(
controller: _c,
focusNode: _focusNode,
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
),
keyboardType: TextInputType.multiline,
cursorColor: Colors.blue,
));
} else if (pb.type == 2) {}
}
I had a similar problem and I solved it in this way.
Try to get your cursor position index in the text via TextEditingController
and with that index get last typed value.
Imagine below example is in TextField
's onChanged
function which gives you inserted text.
Something like this
String key = value.substring(_textController.selection.end-1, _textController.selection.end);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With