KeyEvent.KEYCODE_BACK not matching actual keycode - Java for Android App Development

I'm modifying an IME app for use on Kyocera DuraXV (Hardware buttons).
KeyEvent.KEYCODE_BACK returns 4
But when I press the back button I get the keyCode 67 from the onKeyDown event.
So I tried KeyEvent.KEYCODE_CLEAR in case that's the label on the key. But that returns 28.
So now I'm confused. Is there a way to reverse engineer the keyCode from key press (67) to find out the "label"?

Do you mean 67 decimal? That's KEYCODE_DEL.

Thanks, I confirmed it and you are right.
Now I found another little problem. I'm trying KeyCharacterMap.deviceHasKey(67) and getting false.
Tried it on several keys which I should have, some return true, others don't.

You can use my UsbMode.apk (in the sig).
It's helpful to show you Linux scan codes and Android key codes.

jonas.sj said:
I'm modifying an IME app for use on Kyocera DuraXV (Hardware buttons).
KeyEvent.KEYCODE_BACK returns 4
But when I press the back button I get the keyCode 67 from the onKeyDown event.
So I tried KeyEvent.KEYCODE_CLEAR in case that's the label on the key. But that returns 28.
So now I'm confused. Is there a way to reverse engineer the keyCode from key press (67) to find out the "label"?
Click to expand...
Click to collapse
The keyCode value you are getting from the onKeyDown event (67) corresponds to the ASCII value of the character 'C', not the back button. This is why KeyEvent.KEYCODE_BACK returns a different value (4).
To answer your question, there is no direct way to reverse engineer the keyCode from the key press to find out the label. However, you may be able to infer the label by looking at the other key codes returned by other buttons on the device, and seeing if there is a pattern. You could also try consulting the device's documentation or the manufacturer's website to see if they provide any information on the hardware buttons and their key codes.
Alternatively, you could try using a KeyListener instead of the onKeyDown event to detect key presses, as the KeyListener provides additional information such as the key character and the key code. This may help you determine the label of the key corresponding to the keyCode you are getting.

Related

reprogramming contact key

does anyone know how to reprogram the contact key to open a different program, i would like my to open a different "contact" program each time i press the contact key but instead it opens up the original contact... the one i want to open has pictures contact... the ony way i have been able to open it is by going to where i stored the program on my device...
is there anyway to change it... i did see another post about contact but that didn't solve my delimma...
Here is a link to a soft key applet:
http://forum.xda-developers.com/viewtopic.php?p=226198#226198
It adds a setting in your Control Panel that allows you to change the soft keys to any program you want.
zakhir_n said:
Here is a link to a soft key applet:
http://forum.xda-developers.com/viewtopic.php?p=226198#226198
It adds a setting in your Control Panel that allows you to change the soft keys to any program you want.
Click to expand...
Click to collapse
Thanks zakhir_n!
stylistic14 said:
does anyone know how to reprogram the contact key to open a different program, i would like my to open a different "contact" program each time i press the contact key but instead it opens up the original contact... the one i want to open has pictures contact... the ony way i have been able to open it is by going to where i stored the program on my device...
is there anyway to change it... i did see another post about contact but that didn't solve my delimma...
Click to expand...
Click to collapse
Also check the wiki (http://wiki.xda-developers.com/index.php?pagename=WM5_Tweaks_Other) as there is information on changing the today softkeys:
Change the application launched by Today screen Soft Keys
To change the application launched by the Today screen Left soft key:
HKCU\Software\Microsoft\Today\Keys\112\Open = "\Windows\Calendar.exe" (REG_SZ string, including quotes)
To change the title of the Left soft key:
HKCU\Software\Microsoft\Today\Keys\112\(Default) = "Calendar" (REG_SZ string, no quotes)
To change the application launched by the Today screen Right soft key:
HKCU\Software\Microsoft\Today\Keys\113\Open = "\Windows\Start Menu\Programs\Contacts.lnk" (REG_SZ string, including quotes)
To change the title of the Right soft key:
HKCU\Software\Microsoft\Today\Keys\113\(Default) = "Contacts" (REG_SZ string, no quotes)
Note that 113 normally doesn't exist by default, and probably needs to be created
Also note that there is at least 1 application that allows you to set these through a GUI, developed by FdcSoft called SoftKeyAppletEx.

A Call To Lock/Hardware Button Experts

Hello,
Im currently working on a custom control in managed code(vb.net) and have decided to implement it in a lock application as its initial demo. I have written code which catpures the base hardware keys available to windows mobile(1-6) this captures all of the hardware buttons on my wizard except for the Phone Buttons, Volume/Vibrate Button, and power button. im not particularly worried about trapping the power button because i like the tap to standby feature but im up the creek on the phone/volume buttons.
I found the hardware buttons 1-6 in the registry under (HKLM\Software\Microsoft\Shell\Keys) but i cant seem to find the other keys anywhere including where this person says they are
http://www.mobipocket.com/forum/viewtopic.php?p=2367&sid=c3b2c704a729c2d6e5a47d0ee38ecb54
basically from my understanding of what he's saying the keys for these options(at least the phone ones) should have been listed under "HKEY_CURRENT_USER\Software\Microsoft\Today\Keys\"
I had one key there 112 pointng to my calendar(so that i thought confirmed him) I added a key called 114 with a path to calendar as well. but the button still directs to phone/ so im not sure what's up.
Here's some logic from the hardware button capturing... Any insight into the location of these items would be greatly appreciated
Code:
Dim hk As HardwareKeys = HardwareKeys.ApplicationKey1
Dim i As Integer = 0
While i < 6
Try
Dim hwb As HardwareButton = New HardwareButton
hwb.AssociatedControl = Me
hwb.HardwareKey = hk + i
Catch ex As Exception
Me.Label1.Text &= ex.Message
End Try
i += 1
End While
Dim regkey As RegistryKey =
Registry.LocalMachine.OpenSubKey("Software\Microsoft\Shell\Keys", True)
Me.Label1.Text = regkey.SubKeyCount
For Each skey As String In regkey.GetSubKeyNames
Me.Label1.Text &= skey.ToString & ","
Next
regkey.Close()
Thanks in advance for any insight anyone can provide
DrewG
Well ive found some russian page talking about the
Dated Post on russian site with Broken English Translation said:
HKEY_LOCAL_MACHINE\Software\Microsoft\Shell\KeyMaps]
"195"= - =-hitting "record" on the three pozic. phone (one that najmeshy story)
"196"= hitting "power" and "house"
"197"= Opening screen
"198" = "red tube"
dword:00000000 - nothing
dword:00000001- mobile phone
dword:00000002 - quick menu
dword:00000003 - lock (for the press release #)
dword:00000004 - 00000004 fast-locking
Click to expand...
Click to collapse
Do you guys think this is a good start? At that location i have dword 197 val of 5. Im adding entries now for the othr buttons to see if i can catch
Here's What I have so far for Cingular 8125 HTC Wizard as the hardware buttons/software key maps which i get from a call onkeypress. I believe im going to have to go an unmanaged route for the phone buttons/Volume.
Code:
'not code just looks better this way
SoftKey Left = Key Code 112
SoftKey Right = Key Code 113
Email Button(top left corner) = Key Code 193 (Cf Hardware Button 1)
Web Button(top right corner) = Key Code 194 (Cf Hardware Button 2)
Camera Button(bottom right side) = Key Code 195 (Cf Hardware Button 3)
Voice Button(top right side) = Key Code 196(Cf Hardware Button 4)
Record(hold voice) = Key Code 197(not firing well) (Cf Hardware Button 5)
Comm Button = Key Code 198 (Cf Hardware Button 6)
All of those I can catch and react to but i cant seem to find any info for the phone and volume buttons/ Is there a specific api call I can make thats related to button press or catching? Possibly a way of forcing an association to an app only while its running?
Thanks in advance for any help. Ill post the full app here if i can get over this hump

assign Pop up menu to soft key (windows mobile 5 - smartphone)

I needed to change the text and display a pop up menu for the right soft key on the homescreen. This needs to be done when the our plug-in is selected.
I have tried out various implementation none of them worked or were feasible
>> use SHCreateMenuBar on the desktop window and create the required menu bar in resource. But the problem was that I couldn't revert back to the original menu bar when the focus was passed on to the next plug-in.
>> use SHCMBM_SETSUBMENU. sending this message to the menu bar (HWND) handle with the command id of the right soft key and the handle to the pop up menu did not change anything. I also tried to get the actual HMENU handle to the menu bar using SHCMBM_GETMENU
HMENU hmenu = (HMENU)SendMessage(hMenuBar, SHCMBM_GETMENU, 0, 0);
return NULL and GetLastError() returns 5 (Access is denied).
Also tried a variation with the SHCMBM_GETSUBMENU message
HMENU hmenu = (HMENU)SendMessage(hMenuBar, SHCMBM_GETSUBMENU, 0, commandid);
This returns the same result as above.
Something related to this can be found at
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1362079&SiteID=1
If you are wondering if this is possible you can try out the google homescreen plug-in for smartphone which does exactly that.
http://www.downloadsquad.com/2008/03/20/google-launches-today-plugin-for-windows-mobile/
They change the right soft key to display a pop up menu when the plug-in is in focus dynamically. The default "Contacts" button does not have any pop-up.
Waiting.

noob needs assistance Please be noob friendly.

Hello everyone. My name is tony. First off sorry for being a noob. I should have been learned this. I would like to ask if i could get some help. I want to create a simple calculator that just has a GUI with a grid like layout of clickable buttons at the lower-left-hand side of the activity that has the value 0-9,addition, subtraction,
multiplication,division,decimal, percentage,calculate,clear and clear all . I would like a Text-view above the buttons to display the values of the buttons when clicked. I also would like the result of the calculation to be in the upper right hand corner of the screen that fades in when the user clicks the calculate button .I have searched around and have looked at lots of source code for calculators but there not really "nooob friendlyy"
Some Logic of what im wanting:
user click numbutton -> button pushes its value to Text-View -> user click numbutton -> button pushes its value to Text-View
->user clicks an operand-> Text-View clears its Text on next numbutton press (but still holding that prior value the user entered)->user clicks another numbutton (if they clicked a numbutton it's value would be set to the text-view) or the calculate button -> calculate the two values using the clicked operand and set it to the TextView Result->TextView Result fades in at the top right hand corner of the activity.
Here is were i get
(1)I'm trying to use int/longs and float/doubles depending if the decimal is in the text view when the user clicks the operand.
if is there, expect and return floats and if not, expect and return int's.
(2)parse commands parseInt().gettext().tostring coverts the int to string and respectively for the other data types correct?Is there some benefit to covering to strings?
Rather is it possible to have this implemented using a switch statement?
tone5992 said:
Hello everyone. My name is tony. First off sorry for being a noob. I should have been learned this. I would like to ask if i could get some help. I want to create a simple calculator that just has a GUI with a grid like layout of clickable buttons at the lower-left-hand side of the activity that has the value 0-9,addition, subtraction,
multiplication,division,decimal, percentage,calculate,clear and clear all . I would like a Text-view above the buttons to display the values of the buttons when clicked. I also would like the result of the calculation to be in the upper right hand corner of the screen that fades in when the user clicks the calculate button .I have searched around and have looked at lots of source code for calculators but there not really "nooob friendlyy"
Some Logic of what im wanting:
user click numbutton -> button pushes its value to Text-View -> user click numbutton -> button pushes its value to Text-View
->user clicks an operand-> Text-View clears its Text on next numbutton press (but still holding that prior value the user entered)->user clicks another numbutton (if they clicked a numbutton it's value would be set to the text-view) or the calculate button -> calculate the two values using the clicked operand and set it to the TextView Result->TextView Result fades in at the top right hand corner of the activity.
Here is were i get
(1)I'm trying to use int/longs and float/doubles depending if the decimal is in the text view when the user clicks the operand.
if is there, expect and return floats and if not, expect and return int's.
(2)parse commands parseInt().gettext().tostring coverts the int to string and respectively for the other data types correct?Is there some benefit to covering to strings?
Rather is it possible to have this implemented using a switch statement?
Click to expand...
Click to collapse
You should use Double.parseDouble method

Nook Glowlight 3 keymap

I've taken the liberty of rooking a Nook Glowlight 3 and changing the keymap as follows:
Code:
$ cat /system/usr/keylayout/imx-keypad.kl
key 158 BACK
key 116 POWER WAKE
key 139 MENU
key 412 BACK
key 102 HOME WAKE
key 353 DPAD_CENTER
key 103 DPAD_UP
key 105 DPAD_LEFT
key 106 DPAD_RIGHT
key 108 DPAD_DOWN
key 114 VOLUME_DOWN
key 115 VOLUME_UP
key 90 BUTTON_B
key 191 3
key 192 1
key 193 2
key 194 4
However, when I press the hardware buttons I do not get the expected numeral keypresses. I had based the idea that this would work off this forum post which states:
Renate NST said:
The six hard buttons are mapped in /system/usr/keylayout/imx-keypad.kl
LowerLeft 191 F9
UpperLeft 192 F10
UpperRight 193 F11
LowerRight 194 F12
Power 116 Power
Home 102 Home
Click to expand...
Click to collapse
Of course, I did reset the device after changing the file, and the output seen here is from running cat after the reset so I know that the file was changed properly. Why might the buttons not present the keypresses expected?
For keys to work, you've got:
/system/usr/idc/*.idc - provides links to the other two files
/system/usr/keylayout/*.kl - maps hardware inputs to keys
/system/usr/keychars/*.kcm - maps keys to characters
The first thing to note is that B&N (NTX) just sloppily edited example files.
The imx-keypad.kl has a lot of cruft for things that don't exist.
Ok, they don't do any harm unless there is something wrong with them, then the file reading aborts at that line.
If this were the case, you might have seen a line in the dmesg log.
Get UsbMode.apk out of the signature.
Then you can see where the chain of conversion from hardware input to character fails.
(1, 2, 3, 4 is really not a useful usage of the side keys.
It won't do anything reasonable with any non-custom app.
Page up/page down elicits a response from most things.)
Renate NST said:
For keys to work, you've got:
/system/usr/idc/*.idc - provides links to the other two files
/system/usr/keylayout/*.kl - maps hardware inputs to keys
/system/usr/keychars/*.kcm - maps keys to characters
The first thing to note is that B&N (NTX) just sloppily edited example files.
The imx-keypad.kl has a lot of cruft for things that don't exist.
Ok, they don't do any harm unless there is something wrong with them, then the file reading aborts at that line.
If this were the case, you might have seen a line in the dmesg log.
Get UsbMode.apk out of the signature.
Then you can see where the chain of conversion from hardware input to character fails.
(1, 2, 3, 4 is really not a useful usage of the side keys.
It won't do anything reasonable with any non-custom app.
Page up/page down elicits a response from most things.)
Click to expand...
Click to collapse
Thank you so much Renate. I was wondering what all that cruft was, I will remove it to see if that is preventing further parsing of the file.
In fact, I use the Nook almost exclusively for AnkiDroid, so the 1,2,3,4 are for that app.
Actually, it's more likely that you edited that text file on a Windows CR/LF text editor.
The system will abort as soon as it sees a CR, 0x0d
You can do a hex dump "hd imx-keypad.kl" right on your Nook.
(Use Notepad++ instead.)
Renate NST said:
Actually, it's more likely that you edited that text file on a Windows CR/LF text editor.
Click to expand...
Click to collapse
Very unlikely that VIM on Debian would use CRLF line endings!
dotancohen said:
However, when I press the hardware buttons I do not get the expected numeral keypresses.
Click to expand...
Click to collapse
Well, you're not very explicit on what you do get.
Do you get any response? What?
Did you break your Home key?
Use the UsbMode.apk

Categories

Resources