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.
Related
i am developing android service and I want to know is there anyway that can let me know what is the user typing every key clicked whatever keyboard he is using
for example if the user clicked the letter 'k' from samsung keyboard, i want my service to know that, I could manage this if the user used my custom keyboard, but I want to know even if he is using his default keyboard. and thank you.
I want to know is there anyway that can let me know what is the user typing every key clicked whatever keyboard he is using
NO, there is no way and it's completely illegal.
However Android let you the opportunity the create a custom keyboard using InputMethodService. Once you have created soft custom keyboard and the user have enabled it then you can track every key of user with the callback method onKey()
Also, let me remind you that this is only for the good intentions like word-suggestions and predictions
Is there a way to detect some general keyboard events made by other apps? I understand that the specific keyboard events(e.g. key "b" pressed) should not be exposed due to security reason. But are general events like keyboard show/hide broadcast in any way? I did some search but did not find it available.
Keyboard show/hide is not an event you can listen for, not even in your own app (there are some hacky workarounds within your app, but it seems like you want to do this externally). I don't believe keyboard events are broadcast in any way. They may be delivered to the current Activity window in focus (and to its Views), but I have seen nothing to suggest that they are broadcast across the system.
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
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.
I'm dealing with a phone that has no physical keyboard and I'm using my own custom view for rendering. The device I'm working with, by default, seems to be in a T9 type entry mode where it suggests blocks of text. However, it never sends me the actual key events.
How do I tell whatever soft-keyboard that pops up to enter 'dumb' key event sending mode?
The InputMethodManager has a "isAcceptinText()" call which would tell me if it's in event-sending mode, but not a method to set it. Digging through the documentation hasn't produced any insight. How do I tell the input manager that I only want key events?
I think this page has pretty much all there is to say on Android Input method control: Android - Onscreen Input Methods