Android Dev: Getting key events from onscreen (soft) keyboard - android

I'm developing an Android program to analyze a user's text input and measure typing speed, error rate, average key presses to enter a single character. By doing so, I can compare characteristics of different input methods. To do this, I need to count and record all key presses made by the user during the text entry process.
For example, a user using a basic qwerty keyboard would have to press at least one key for each letter. However, a user using a keyboard with word completion would need to press fewer keys. But how many key presses are made (on average)? Does word completion actually improve typing speed? These are the questions my program will help answer.
Reading other posts, I know that (by default), onscreen keyboards don't send key events for all key presses. Physical (hardware) keyboards do, but most mobile devices don't have a physical keyboard. I also know that I can implement a TextWatcher to detect when a letter is typed in an EditText field. However, some IMEs might require the user to press a sequence of keys to enter a single letter (or word). I need to handle the intermediate key events (i.e., by counting and logging key presses).
My question: How would I capture every key press event from an IME (even events that don't trigger a typed character) without modifying the IME's user experience (e.g., auto completion, word prediction, T9 disambiguation, etc.)? Is this even possible?
Thanks in advance for your time.

Is this even possible?
Only by writing your own IME, AFAIK, or getting the source to an existing IME and instrumenting it.

did you try to listen for TouchEvents?
did you try to use onKeyPreIme() from View class? with this one you can catch key presses before they are consumed by the IME

Related

How to store the number of time each key pressed in android?

Sorry for asking this type of a question. I'm a newbee to android and i have this idea to develop an app to detect stress based on dwell time and flight time of the keys. Is there a way to get these values through a background service ? I'm aware about creating an intent service and using alarmManager to run this service only during a certain time of the day. but the core part is missing as to get dwell time and flight time of keys pressed in the keyboard.
Is there a way to get these values through a background service ?
No.
get dwell time and flight time of keys pressed in the keyboard
Write your own input method editor. Then, convince users to use it.
Bear in mind that many existing input method editors actually use long-press events for different keys (e.g., long-press U to get 7 without having to switch to a separate set of keys). Other input method editors use gestures, where the finger does not leave the keyboard. In other words, the concepts of dwell time and flight time — originally developed for physical keyboards — would have to be revisited for soft keyboards anyway.

Google keyboard doesn't call commitText() on pressing Enter

I have written a custom InputConnection by extending android's BaseInputConnection. I used to get commitText() when the user presses Enter Key. But recently with Google Keyboard, this doesn't happen. Google Keyboard sends sendKeyEvent() with the parameter being enterKeyUp and enterKeyDown events. However, I don't get the predicted text, as I used to get in commitText(). How can I get the predicted text on pressing EnterKey in Googke Keyboard?
Did they actually have a composing region? If not they may have decided no commit text was necessary. Or did you tell them your input type was NULL? If so, they may have gone into dumb mode and sent everything as key events.
They also may have called FinishComposingText instead, which tells the editor that the existing text is good (no correction). But its generally not a good idea to assume a certain action will come from a certain event because keyboards are always working around bugs in bad input connection implementations to get the effect they want. Just implement InputConnection as best you can and do what it says, rather than expect certain events at certain times.

Get software key presses in a service

I'm trying to develop an app that, according to some pattern pressed on the keyboard (like swipe, but not that complex), it will do some action. For example, if the user presses two keys at once, it will do some action. This has to be a service, because my won't have a gui. It will just do the actions. I read that it's not possible, as it would create a security hole, so I'm open to suggestions on how I can tackle this problem. I've thought of this way:
1. Create an accessibility service and get the key events (easy for hard keyboard, but I don't know about the soft keyboard.)
Could you give me any other ideas, or help me on how to get soft key events in an accessibility service?
Thanks!

Android: Global Key Listener

I am writing an android app which will record the frequency and timestamps of when a user is using their keyboards (soft or hard) (Example: a parent checking to see if their child was texting during school by giving them timestamps and frequency of key presses). This wouldn't need to know what was being typed, just when something was typed. It would also need to function regardless of what app was using the keyboard.
This is not possible, except perhaps via custom firmware.

Key event handling process

I'd like to know how the key event is handled in Android platform.
From 'when user type key 'a' on software keyboard',
To 'view draw the character 'a' on itself'.
Probably, the key event is generated by IME,
And it will be sent to parent view,
Finally, view(such as EditText) displays chracters.
Please somebody explains about these entire key event handling process.
Take a look at this article: http://developer.android.com/resources/articles/creating-input-method.html
Basically, you can either manually send KeyEvents or you can manually edit and commit text around the cursor in the application's Input View.
These are all done via your IME's InputConnection.
OnKeyListener and OnKeyDown do not get called, as you have discovered, when using a software keyboard. They only get called when using a hardware keyboard, which many Android devices don't even have.
I assume what you are trying to do is capture key events as they are occurring in an EditText area. Your best bet in this case, in order to handle both software keyboard input and hardware keyboard input, is to register a TextWatcher via the addTextChangedListener() method.
Note that on phones with Android 2.1 and later, such as the Nexus One, people have the option of using speech recognition to input text into your EditText instead of typing the text. When they do that you may get full words, or even full sentences, entered all at once. So you need to check the entire contents of the EditText field when there is a change to the contents.

Categories

Resources