I have an Ionic (5) app and I want to detect a long press on a key (keyboard) when the app is running on a mobile device (I'm testing on Android).
I added (keyup)
and (keydown)
to a ion-input
, and when I run the app on browser I'm able to get the time difference between the first keydown event (if I long press on a key, keydown is firing multiple times) and the single keyup event that i receive when the key is released.
Unfortunately, this solutions isn't working on mobile (Android), I only receive one keydown event and one keyup event that fire almost at the same time, even if I press the enter key for more than 5 seconds or so.
I don't think any code is needed, since this one is more a conceptual question.
How can detect a long press on a mobile keyboard?
CodePudding user response:
In android this isn't going to work. It's just not how the keyboard interface happens. By and large, keyboards don't actually send key events in Android. They send commitText messages, which just send a string to the text field. Anything turning it into key up and key down events is in the Ionic framework. Since the keyboard doesn't send key events, the app can't know how long they pressed the button. They keyboard doesn't send that info. So the Ionic framework that's making the key events can't give you that info either, there's no data for it to extrapolate from.
You're going to have to come up with a different UX design, this will never work on Android.