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.
Related
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.
Base on Hacker's Keyboard, I want to send text from GCM (Google Cloud Messaging) to current input (textbox).
So, how can I trigger onText event on LatinIME.java to send text (through CharSequence text to current input)
public void onText(CharSequence text) {...}
That's not how you would do it. LatinIME is a specific keyboard- Google's. It may or may not be installed (Samsung doesn't use it). And the input connection is something that exists only to talk to the IME because its a separate process. Its also pretty much a 1 way interface- you don't cause text events in the keyboard.
You're also overthinking things. This is your app. Just use setText() on the view. If you want this to happen even outside your app, you couldn't do that anyway (the keyboard only communicates with a single app at a time).
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.
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'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