2

in my application I would like to receive touchEvent(MotionEvent) event while the user is typing using his soft keyboard on a TextView. I have already tried using dispatchTouchEvent(MotionEvent) on the main activity, but during the typing this event is not fired. Is there a way to handle it?

EDIT: The main idea is to have from the soft key two different events, one for the letter submitted (for example as with keyUp and keyDown) and one relative to the touch like dispatchTouchEvent, since when you press for a letter you touch the screen, meaning that you should arise a dispatchTouchEvent or something similar.

Matteo Ciman
  • 213
  • 1
  • 3
  • 7

1 Answers1

3

It's not possible to get touch events from the soft keyboard as Android keyboards are basically separate Android apps that already consume their touch events. However you can react on their key presses using the onKeyDown and onKeyUp events. See also http://developer.android.com/training/keyboard-input/commands.html

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
  • And there is no way to override this behavior?? For example create my custom soft keyboard to use with the EditText and override only the interesting methods? Moreover, onKeyDown and onKeyUp are usually fired by a hardware keyboard, not a software one like the softkeyboard. – Matteo Ciman Sep 21 '14 at 16:29
  • `onKeyDown` and `onKeyUp` are supposed to be fired also for soft keyboards. Please clarify what you want to achieve at the end. – Lars Blumberg Sep 21 '14 at 16:52
  • I want to events..or at least one..one for what the user clicked on the keyboard ('a', 'b' or what else) and another one that is referred to the touch (so, a sort of dispatchTouchEvent related to the touch of the character of the soft keyboard). – Matteo Ciman Sep 21 '14 at 16:56
  • Please add code to your question that shows how you deal with `onKeyDown` and `onKeyUp`. Still your objective is not clear to my why you need touch events. Maybe your objective can be achieved in a different way. – Lars Blumberg Sep 21 '14 at 17:35
  • The code about keyUp and keyDown is not essential, since the biggest problem still remains: if I can have even a dispatchTouchEvent when the user click on the soft key. – Matteo Ciman Sep 22 '14 at 07:59
  • 3
    @LarsBlumberg it is explicitely stated in the docs that `onKeyDown` and `onKeyUp` are not meant to be used for the software keyboard. Also the first one will not work for most of the keys either. And even if it did, it does not really solve his problem nor mine. I need the time the user touches the screen and when he releases the button. Those two methods even when using `dispatchKeyEvent` won't provide that result. – keinabel Nov 15 '16 at 02:42