Capture all Ctrl-? under Android - android

I'm modifying ConnectBot to take advantage of hardware keyboards and I need to capture all Ctrl-? presses. I've disabled all of the alphabetic menu shortcuts (such as Ctrl-C for copy) but the key presses still don't seem to be being received by the onKey event.
I'm fairly new to Android development (literally started today to fix ConnectBot to handle hardware keyboards) and quick Google searching doesn't seem to turn up anything about capturing Ctrl-? key presses.
How do I tell Android to pass these straight through to the onKey handler?

It turns out that the keyCode was set to the correct character value (e.g. 'C'). However, the result of getUnicodeChar() was 0 because CTRL was being held.
All that was needed was to add handling to get the unicode character regardless of the meta-keys that are being held down with:
if (event.isCtrlPressed())
event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
Then later on it was necessary to encode the "CTRL is being held down" information in the key data that was being sent, which was already functionality provided by the ConnectBot code.

Related

Detect long press on keyboard key (Ionic, Android)

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?
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.

Unable to get key events for touchscreen keyboard from /dev/input/event1

I am unable to get key events from /dev/input/event1. What i'm able to filter out from its output is absolute X and Y touch coordinates from event code 53 and 54. I'm confused why there's no output with event code 1 when i type on my soft keyboard. I want to know which key user presses and with how much pressure. Hope you understand my problem.
I'm on rooted Samsung Galaxy S4.
Because the soft keyboard doesn't work like that. It isn't a part of the OS, its an application. So the keyboard app will be given touch events, and it will call java functions to tell the main app what was pressed. It doesn't go through hardware input channels at all after the press. The OS doesn't know what keys are where, ever.
Most keyboards don't even generate key events- they generate word at a time output via commitText.
Basically, you can't do what you want in the way you want. The only way to know what keys were pressed, without altering the OS, is to be on the other side of the InputConnection processing commands from the InputMethodService (keyboard).

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

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

Detecting button type of front nav keys

I would like to detect if the navigation keys of the front of the phone (Home,Menu,Back,Search) are hard-keys (ex. G1) or soft-keys (ex. Nexus One).
This api /android/content/res/Configuration.html#keyboard gets close but is related to the keyboard and not the front facing keys.
KeyEvent (http://d.android.com/reference/android/view/KeyEvent.html) has a FLAG_VIRTUAL_HARD_KEY flag, I can only detect that after the key is pressed. I'd like to find out what type of buttons the user has without asking the user to press a key first.
I would have expected such an api to be under /android/hardware/package-summary.html but android.hardware has very little info about the actual hardware of the device.
sorry for incomplete links...
apparently there is not an API for that...
source: http://groups.google.com/group/android-developers/browse_thread/thread/10f031e9d52df4f8

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