[Q] Capture raw soft-keyboard events - Android Q&A, Help & Troubleshooting

Hi all
I have an issue with an app I am writing. It has the working name VNCHID, and is designed to allow an Android phone/tab to be used as a keyboard and mouse for a computer (or other device) over VNC. I currently have it in a semi-working state, but with unpredictable results. I am hoping someone can help with the issues I have come accross.
The first is related to mapping KeyEvents to VNC (X11) KeySyms. I have derived a class from KeyEvent wrich adds a method "getKeySym". This method does the following:
Uses the getUnicodeCharacter method from KeyEvent to try to determine a character from the key (combination). If one exists, it uses a map (found elsewhere) to translate this into a KeySym.
Does the same again, but without modifier keys. This may be unnecessary, but for now I have left it in.
Assuming the above fails, it uses getKeyCode and runs this through my own map to generate a KeySym.
The problem I am facing on my development device, an A10-based tablet running CM9, is that if a key is pressed which doesn't have a unicode character associated with it, like backspace, the code just stops at getUnicodeCharacter. It doesn't crash the app, throw an exception, or anything else, the execution of the routine just stops completely. It will still pick up other keyevents afterwards.
This seems very strange, and I do not know why it would do so.
My second problem is on my day-to-day phone. I tried installing the app on here to see if the problem was with the device/ROM/etc, but on here it doesn't even detect any keyevents. I have done some research which indicates that my approach (implementing OnKeyListener) is not guaranteed to work with soft keyboards, but it seems very strange that it (almost) does on one device but not on another (using the same soft keyboard, hackers keyboard).
I am now almost at the stage of creating my own keyboard (not an IME, just a layout to be shown in the app with a keyboard), but would like to avoid this. Can anyone help? I am tearing my hair out. Does anyone know the correct way to receive keyevents from a soft keyboard? I do not want an edittext, I just want the raw key events.
The code for my getKeySym() method is bellow. It stops at the first getUnicodeCharacter() call when a non-character key is pressed:
Code:
// Test unicode
Log.i("VNCHID.VKE","Translating keyevent to keysym");
int keysym=0, ucc=0;
ucc=this.getUnicodeChar(this.getMetaState());
Log.i("VNCHID.VKE","Got ucc");
if( ucc > 0 ) {
keysym = UnicodeToKeysym.translate(ucc);
}
if( keysym > 0 ) {
Log.i("VNCHID.VKE", "Got keysym "+keysym+" from ucc "+ucc);
return keysym;
}
// Test unicode without modifiers
ucc=this.getUnicodeChar(0);
if( ucc > 0 ) {
keysym = UnicodeToKeysym.translate(ucc);
}
if( keysym > 0 ) {
Log.i("VNCHID.VKE", "Got keysym "+keysym+" from ucc wom "+ucc);
return keysym;
}
Log.i("VNCHID.VKE","Could not find keysym from ucc, trying from keycode");
// Otherwise lookup from KeyCode
if( KCSM.size() < 1 ) generateKeyCodeSymMap();
/*KCSM.
if( KCSM.containsKey(this.getKeyCode()) ) return KCSM.get(this.getKeyCode());
*/
keysym=KCSM.get(this.getKeyCode(), -1);
Log.i("VNCHID.VKE","Result of lookup by keycode "+this.getKeyCode()+" is "+keysym);
return keysym;
Note it was much simpler, but I have expanded it and inserted the Log calls for debugging. As an example, when backspace is pressed I receive log lines from my onKey method, plus the first one in this method (Translating keyevent to keysym) but nothing after that.
Please help!

Hi
Is this the right forum to be asking questions like this? I'm not trying to be pushy, it's just I've come to expect quick, helpful answers on this site, so I just wanted to double check.
If so... Bump
If not, could someone please point me towards the appropriate forum?
Sent from my MB860 using xda premium

Related

Key definition set (keyboard layout) patcher for stock xv6850

- Note -
You'll probably need to know your way around a hex editor and be able to read basic C in order to make much use of this post. That's the breaks right now. Someone else might decide to make a friendly GUI to wrap things, but right now, this program isn't particularly user friendly.
If, however, you know your way around C, then you might be interested in this post. Feel free to read on if not, though don't expect a lot of help if you're not fluent in the basic prerequisites here, as this project is very much in its early stages.
Incorrect usage of this program can easily crash your phone. Please be sure to read and understand the entire posting before deciding to actually try the program out.
--
I have written a program, keypadpatch.exe, that will patch the microp keyboard tables in the stock Verizon xv6850 keyboard driver. Unlike normal keyboard remapping programs, you can create your own Fn+key combinations on keys where there were previously none. This was important for me as there are a lot of keys on the RAPH500 keyboard without Fn+key combinations, and the keyboard was missing quick access to important keys like semicolon or underscore.
The keyboard layout patcher program will modify the key definition tables in device.exe's instance of keypad.dll. The modifications are done in RAM, so they don't persist across boots. (You could re-run the patching sequence automatically at every boot to make your changes stick if you wish, once you are comfortable with a modified key definition set.) The main advantage of this is that if you happen to break something in the keyboard driver while developing a new set of key definitions, you'll just need to reboot the phone to get things back to normal as opposed to perhaps having to hard reset the device and replace a hex edited driver dll.
The keyboard layout patcher program hardcodes offsets that are specific to the xv6850 keyboard driver. Please don't try it on any other device or firmware combination other than the initial stock Verizon firmware for the RAPH500. Running keypadpatch.exe on any other device or ROM image will likely crash the phone (likely fixable by rebooting it).
The program itself is fairly rough around the edges and developing a new full key definition set is likely not for the faint of heart. Please don't ask me directly for help with making a key definition set.
The program operates in two modes. The first mode will attempt to dump out the currently active key definition array from the running keyboard driver and save it into a file called "microp" (no extension). The file will be placed in the directory within which keypadpatch.exe resides. You will get a confirmation message box if everything works in this mode of operation.
The second mode of operation will read a key definition set file called "microp" from the directory within which keypadpatch.exe resides, and then replace the key defintion array in the keyboard driver's memory image with the one from the key definition set file. If everything works, you won't see any message boxes or any other confirmation. However, if something failed, then you'll either get an appropriate error message, or if you gave keypadpatch.exe a sufficiently invalid microp file, something will probably have crashed. Use carefully at your own peril!
If there is a "microp" file in the directory where keypadpatch.exe resides, the program runs in the second mode of operation (loading a new key definition set). Otherwise, it runs in the first mode of operation (dumping the current key definition set).
Modifying a key definition set involves popping a "microp" file open in a hex editor and twiddling fields by hand right now. There is no friendly program or GUI to make things easier than that.
For the RAPH500, the key definition set is an array of 0x3A elements, each of which is described by the following structure layout:
Code:
#define MICROP_KEY_FLAG_VIRTUAL_KEY ( 0x80000000 )
typedef struct _MICROP_KEY_DEFINITION
{
//
// Virtual keys for primary button press.
//
// { MappedVK, IMEVK, RepeatVK }
//
ULONG VirtualKey[ 3 ];
//
// Secondary characters for function combinations. Set the
// MICROP_KEY_FLAG_VIRTUAL_KEY bit to indicate that the value is actually
// a virtual key code and not a character code.
//
// { Fn + key, 123-mode key, ... }
//
ULONG FunctionChar[ 11 ];
///
// Unknown.
//
ULONG KeyId[ 2 ];
//
// Callbacks to execute when the key is pressed instead of simply inserting
// a key or character code into the input stream. The addresses should be
// valid code within device.exe.
//
// [ 0 ] - Not for Fn- combos.
// [ 1 ] - ??
// [ 2 ] - Not for Fn-combos.
// [ 3 ] - ??
//
ULONG_PTR Callbacks[ 4 ];
} MICROP_KEY_DEFINITION, * PMICROP_KEY_DEFINITION;
Many of the fields of this structure don't currently have a known meaning attached to them. If you figure out what they do, perhaps through disassembly or debugging, or simply trying them out and seeing what happens, I'd appreciate it if you'd post back in this thread.
The fields that do have a particularly relevant meaning are:
- VirtualKey[0], VirtualKey[1]: These need to be set to the virtual key code (VK_* constant) for the virtual key event to generate then the particular physical key is pressed. Usually, the first two VK values are the same, but in some cases (the enter key, for example), they differ. The file \Windows\eT9.Raphael.wwe.kmap.txt may have some clues as to VK-codes for special keys on the RAPH500 (i.e. the "launch tmail.exe key"). Note that VK-codes for numeric keys (0-9) and alphabetical keys (A-Z) are simply the ASCII values for those characters (alphabetical keys always use uppercase characters). See the above link on VK_* constants for more details.
- FunctionChar[0] is the character value (not virtual key code) to generate when a particular physical key is pressed when the Fn-key is active. Normally, this value is simply the raw character code in question (e.g. 0x20 for space, 0x41 for capital A, 0x21 for !). However, if bit 0x80000000 is set, then this value appears to be treated as a virtual key code and not a character code. Using a VK-sequence might be useful if you wanted to map an Fn-key combo to, for example, soft key 1 or soft key 2. Using a character value might be useful if you want to map an Fn-key combo to, for example, semicolon. The keyboard driver takes care of injecting any necessary shift states to make a given character value appear when you provide a raw character value here. For example, setting FunctionChar[0] to 0x21 for a particular key will cause a VK_SHIFT + VK_1 key down / key up sequence to be sent to generate a ! character.
- The last four fields, "Callbacks", desire a little bit of special mention. These are function pointers into device.exe's address space for callbacks that get invoked when a key is pressed. This is how the dedicated "launch tmail.exe" key, and the Fn-Space combo to launch CommManager.exe work on the RAPH500. Setting a particular value to NULL means that the key will be injected into the normal input system instead of being handled by a function call. As a special exemption, keypadpatch.exe accepts the magical value of 0xFFFFFFFF for a particular callback pointer to mean that the currently active callback pointer in device.exe memory space should be left alone. Any other value replaces the active callback pointer in device.exe. You will generally never want to touch this value except to NULL it out for a key that you'd like to reclaim from one of those hardcoded built in shortcut keys.
As I haven't discerned all the meanings of the fields in the key definition structure, there may be additional capabilities (or limitations) here. I've only so far attempted to perform simple tasks like create an Fn-key mapping on the Z key to generate a ' character, where there was no mapping before. It is possible that some special keys might have additional hardcoded handling elsewhere in the keyboard driver and thus might not necessarily be overridable with this method.
Some of the keys in the stock key definition set don't appear to be used for the RAPH500's physical keyboard. For example, there is a "tab" key lurking, despite there being no physical key which uses that definition slot.
Download link for keypadpatch.exe + some example key definition files, one for the stock RAPH500 layout and one that maps Fn-A to -, Fn-S to ", Fn-z to ' in the start of porting something similar to the TITA100 layout to the RAPH500:
http://www.nynaeve.net/Skywing/xv6850/keypadpatch.zip
Acknowledgements:
cmonex provided some invaluable assistance with getting the ball rolling on this project.
- Reserved for future updates. -
Posted a slightly modified key definition set: http://www.nynaeve.net/Skywing/xv6850/keys2008120301.zip.
This key definition set makes the following changes:
Code:
Key New function Old function
=======================================
Fn+Z Left soft key Unassigned
Fn+X Right soft key Unassigned
Fn+S Underscore (_) Unassigned
Fn+D Tab Unassigned
Fn+C Semicolon (;) Unassigned
Mail OK/done Start tmail
Fn+Mail Ctrl* Start tmail
(* Key combinations marked with a * may not be fully working yet.)
Thanks skywing!
This worked great for me, the _underscore_ was especially needed.
Anything else you want me to test? gps?
I'm off work for 5 days in a row so I can play with the phone without too much fear...
_________________
VZW TP - XV6850
I'm still fiddling around with this, I'll probably work on some simple tools tonight to help translate the keymap files to/from a more human-readable format.
/Andrew
kilozebra said:
I'm still fiddling around with this, I'll probably work on some simple tools tonight to help translate the keymap files to/from a more human-readable format.
/Andrew
Click to expand...
Click to collapse
Note that the position in the key definition array isn't what controls what physical keys map to which key definiton slots. That seems to be controlled by the first value in the array (first VK identifier), according to basic tests. Let me know if you discover something more definitive about that, though.
Would this tool work to remap the keys if applied on a non-Verizon CDMA ROM? I'm especially looking into putting Alltel MR1 ROM release on my Verizon TP and fixing the keyboard after that.
TIA

Get text from external keyboard connected to tablet

Hi,
I want to get some text from a keyboard connected to a tablet but I don't want to use an EditText.
With the following event I can handle keys like enter, space-bar, return, arrows but not characters like 'a','b', etc...
public boolean dispatchKeyEvent(KeyEvent e) {
Log.d("KEYBOARD",e.toString());
return true;
};
I need to wait for the user to input some text but I want it invisible to the user. I open a msgbox, ask for some text and only after manage the text I show it to the user. Basically I need some event like the one above but for all keys.
Thanks

[Q] activity change problem

Hi!
I'm developing an android app. This app have got 3 activity. On the first activity i have two button. the first button is navigate the user the second activity, and the second activity navigate to the third activity.
the second button on the first activity is use the phone camera, and i would like to navigate to the third activity, but my app dont do this.
If i click on the second button on first activity the app show me the third activity, and after the third activity show me the camera.
I use this code to change activitys:
Code:
Intent kapcsolat = new Intent(v.getContext(), SECONDACTIVITY.class);
startActivity(kapcsolat);
and i use this code to use the phone camera:
Code:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileuri = getOutputMediaFileUri(KEP);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileuri);
startActivityForResult(intent, kamera_kep);
My second button code:
Code:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileuri = getOutputMediaFileUri(KEP);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileuri);
startActivityForResult(intent, kamera_kep);
Intent kapcsolat = new Intent(v.getContext(), SECONDACTIVITY.class);
startActivity(kapcsolat);
Could you help me in my problem?
Now my app work as this:
First activity -> second button -> Third Activity -> Camera activity
But i would like to work as this:
First activity -> second button ->Camera activity -> Third Activity
sorry for my bad english, i hope you understand me.

[Q] App to perform the same effect as the touch button task shifting

Good evening, I'm a newbie, I read about intent, activity and other things in Android but can not get the effect I want.
I would make exactly the same action that causes the button to the left. "switch between tasks" of a Galaxy Tab 4. Run the code in my application and pass to any previously opened application.
I've tried several codes like this, and I've also searched some information about the PID of the process, but I know not to handle them too well:
Intent intent1 = new Intent(Intent.ACTION_VIEW); // OR ACTION_MAIN ??
intent1.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT );
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager manager = getPackageManager();
intent1 = manager.getLaunchIntentForPackage("com.other.externalapp");
startActivity(intent1);
PD: This code works, but it opens a new instance of "com.other.externalapp" and not what I want, it close an internal connection of "externalapp". I want exactly the same effect achieved with switching between applications with the Galaxy tab touch button.
Maybe it's a permission problem, or to be able to run the exact same PID already open.
Thank you very much for your help people. :good:

[Q] Admob event is not firing sometimes, or is firing, but not completely

I use Admob's rewarded video ad. It can be called by button from my game's pause menu and game over screen. So it works almost always in pause menu, and it's worse on game over screen. So, here's the event handler code:
Code:
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
this.RequestRewardBasedVideo();
Lives.lives++;
rewardButtonP.interactable = false;
rewardButtonG.interactable = false;
GameObject.Find("banner").GetComponent<AdBanner>().bannerView.Hide();
if (!pauseUI.activeSelf)
respawn.RespawnAction();
}
Bug 1: Button is always non-interactable if ad is not loaded, but sometimes it is interactable, and nothing happens on click. It looks like 1st, 3rd and 4'th lines were not called.
Bug 2: Sometimes respawn.RespawnAction() is not called from game over screen (it must be called only from there). And it is 100% that !pauseUI.activeSelf.
These bugs are seemed to be random.

Categories

Resources