mohasad

hi all ,
i am having a great issue in handling windows mobile 5.0 smartphone devices having QWERTY keypads . because in all these devices , the number keys are embedded in differant keys . my application is fully number oriented . so when a user presses a key where the number is embedded , it should give the keycode of corresponding embedded number . so i have tried out with the following code :

[DllImport("coredll.dll")]
protected static extern IntPtr ImmGetContext(IntPtr hWnd);
[DllImport("coredll.dll")]
protected static extern Boolean ImmSetOpenStatus(IntPtr hWnd, Boolean fOpen);
[DllImport("coredll.dll")]
protected static extern UInt32 ImmEscape(IntPtr hKL, IntPtr hIMC, UInt32 uEscape, IntPtr lpData);
[DllImport("coredll.dll", EntryPoint = "GetFocus")]
private static extern IntPtr GetFocus();
protected static readonly UInt32 IME_ESC_SET_MODE = 0x0800;
protected static readonly IntPtr IM_NUMBERS = (IntPtr)2;
protected IntPtr hC = IntPtr.Zero;

protected IntPtr GetHandle1(Control ctrl)
{
IntPtr handle = IntPtr.Zero;
ctrl.Focus();
handle = GetFocus();
return handle;
}

protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
hC = ImmGetContext(GetHandle1(this));
ImmSetOpenStatus(hC, true);
ImmEscape(IntPtr.Zero, hC, IME_ESC_SET_MODE, IM_NUMBERS);
}

protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
ImmSetOpenStatus(hC, false);
}
.

but the above code is also not working . moreover my application is in .Net Compact Framework 1.0 .
so what i am trying to do is making the keyboard to give only numeric values .
so i have planned to use hidden edit controls . is there any way to use hidden controls . if so give me the link or code , so that i can learn .
or if it possible to make the above code working generic to all devices having QWERTY keypads , please give me the code.

thanks
sadiq




Re: .NET Compact Framework using hidden controls in the form

AlexY

On the WM Smartphone devices with the QWERTY keypads the mappings between the letters and numbers are stored in the registry. (Take a look at the Mike's post here)

The mapping are located in:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Shell\PhoneKeyMatch\PhoneDigits]

In the following form:

# 47

* 41

9 43

8 58

etc... Where the key codes represented in a hex format. So you should be able to read these mappings in your program and do appropriate translations.





Re: .NET Compact Framework using hidden controls in the form

mohasad

hi Alex,
thanks. is these will be in the phone registry.If so how to access or view those entries .can u give some sample code that will work only on QWERTY keypads, i.e allowing the numeric input .
waiting for your reply .

thanks
sadiq






Re: .NET Compact Framework using hidden controls in the form

mohasad

hi,
i want to know how to do this step by step . Moreover as you said , on looking up the registry entries we can handle appropriately . but it will changes inh differant devices But i want to handle in a generic way so that all the devices having QWERTY keypads will support my application . waiting for your reply .

thanks
sadiq





Re: .NET Compact Framework using hidden controls in the form

AlexY

The settings will be different on a different devices, but the location in the registry should be the same. It should be possible to create a generic code that will read this key from the registy populate some data structure (it could be Dictionary) and use that to map the keys.

P.S. Do not expect somebody writing the code for you.





Re: .NET Compact Framework using hidden controls in the form

mohasad

hi ,
moreover i tried to see the registry entries using regedit . i cannot find the registry key that u posted .. can u figure out how u to see the above entries in the registry
what i mean is not the code for my application , i just asked for a link for a sample such that i can learn the way of doing things. .
thanks
sadiq






Re: .NET Compact Framework using hidden controls in the form

mohasad

hi alexy,
just give me a sample code to acess the key '1', the key combination , so that i can do with other numbers . i got very much struck .. i have searched through the net . but couldnt find any related one.

thanks
sadiq






Re: .NET Compact Framework using hidden controls in the form

AlexY

The code could look something like that (untested):

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Shell\PhoneKeyMatch\PhoneDigits");

string[] names = key.GetSubKeyNames();

Hashtable map = new Hashtable();

foreach (string name in names)

{

int value = int.Parse(key.GetValue(name).ToString(), NumberStyles.HexNumber);

map.Add(value, name);

}

// And then in your KeyDown event handler:

private void textBox_KeyDown(object sender, KeyEventArgs e)

{

if (map.ContainsKey(e.KeyValue))

{

txtUrl.Text += map[e.KeyValue].ToString();

}

}





Re: .NET Compact Framework using hidden controls in the form

mohasad

hi,
i have tried out with the following code .
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Shell\PhoneKeyMatch\PhoneDigits");
string[] names = key.GetSubKeyNames();
foreach (string name in names)
{
int value = int.Parse(key.GetValue(name).ToString(), NumberStyles.HexNumber);
map.Add(value, name);
}

private void textBox_KeyDown(object sender, KeyEventArgs e)

{

if (map.ContainsKey(e.KeyValue))

{

txtUrl.Text += map[e.KeyValue].ToString();

}

}

i tested with Motorola Q emulator. but while debugging , i come to know that the value of
key.GetSubKeyNames() is ' 0 ' . but the value count is 8.
the various entries for the values are as folows:
9 - 57,58,59,5a
8 - 54,55,56
7 - 50,51,52,53
6 - 4d,4e,4f
5 - 4a,4b,4c
4 - 47,48,49
3 - 44,45,46
2 - 41,42,43


i dont get anything from this . wheather anyone give a clear idea .

thanks
sadiq





Re: .NET Compact Framework using hidden controls in the form

AlexY

OK, here's corrected code:

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Shell\PhoneKeyMatch\PhoneDigits");

string[] names = key.GetValueNames();

foreach (string name in names)

{

int value = int.Parse(key.GetValue(name).ToString(), NumberStyles.HexNumber);

map.Add(value, name);

}

The Moto Q emulator's settings are wrong. On the actual device is what I showed you.





Re: .NET Compact Framework using hidden controls in the form

Christopher Fairbairn

Hi guys,

I just thought I would pipe in here with something I have learnt in the last few days while researching this problem a little further.

In a great blog entry titled How do you dial 1-800 flowers which kind of outlines this problem (which only tends to affect devices which have the numeric keypad overlaid on top of the qwerty keypad), you can find some additional information in the comments which make an interesting read.

... wrote:
Matthew and Joe, I went searching for the ISV mechanism for you folks to make use of the number table, and discovered that the story is really messy in WM5. There is no consistent way to do it across WM5 devices, and no exposed way for ISVs to even use the various things we do have. )-:

In WM6 we've exposed a mechanism for ISVs to explicitly put the keyboard into number mode (SHSetImeMode). Given that we're not helpful for WM5 (and sorry about that), will the new WM6 method meet your needs in new devices If not, can you tell us more about what you're trying to do (you can use the "Email us" link if you don't want to say publicly) so we can understand your needs

The new SHSetImeMode API is documented here http://msdn2.microsoft.com/en-us/library/bb431863.aspx and looks like it neatly resolves the issue by allowing a programmer to programmatically enter the hardware keyboard into numeric mode.

Even worse for those thinking of using the solution (looking up the mapping table stored in the registry) as proposed by Alex...

... wrote:
Thanks Matthew. I've forwarded your scenario on to our designers so they can mull it over. I asked them if it would be okay to point you at the table in the registry. But that wouldn't be good because we moved it for WM6 (I guess the fact that we were planning to move it was one of the reasons we didn't publish the location in WM5).

This problem is also discussed in the following threads http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1114869&SiteID=1 and http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1114869&SiteID=1

Hope it helps,

Christopher Fairbairn






Re: .NET Compact Framework using hidden controls in the form

mohasad

hi christopher ,
then whats the solution . wheather we have to go by device wise build . if so how many QWERTY devices are available .. its not easy to tackle it in CF 1.0 . what abt the ImmGetContext .

thanks
sadiq





Re: .NET Compact Framework using hidden controls in the form

Christopher Fairbairn

Hi sadiq,

mohasad wrote:
then whats the solution . wheather we have to go by device wise build . if so how many QWERTY devices are available .. its not easy to tackle it in CF 1.0

It's not easy no matter what development environment you are using. This is simply an area which seems to have little OS support for third party ISVs, or atleast (as it seems to be the case) until you can target Windows Mobile 6 devices with the new API present.

Over time there are becomming less and less of these areas in the Windows Mobile OS, but there are obviously still some as this series of (very similiar) threads has shown.

I guess your only solution is to use code similiar to that provided to you by Alex to read the mapping from the registry (if it exists) and fail gracefully in the case where you can't find the table.

However you will have to test it on each device type you want to support to ensure that your registry reading code works correctly in all cases. It's possible that the table is in slightly different locations on different devices, or contains a slightly different format of data etc. You should be able to extend Alex's code to cope with most of these cases to get one applicaton which works on a wide range of devices. For instance you could search for the table in one location within the registry, and if it is not found there you could move on to probing another possible location until you finally find it or have given up having tried all known locations.

Alternativly you may forgo trying to read the table out of the registry at all, and simply implement your own lookup table for each device type you support. Then the challenge becomes detecting at runtime which device type the application is running on.

As some of the comments have said, one of the reasons the registry key wasn't fully documented was the fact that it was an internal implementation aspect of the platform which wasn't meant for ISV access. It appears however that the mechanism for "clean" ISV access to this functionality was only provided with Windows Mobile 6.

I don't think you'll find a nice clean single API call etc to resolve your situation until you can say you only support Windows Mobile 6 devices or higher - which is probably some time off in your case by the sounds of it.

Sorry,

Christopher Fairbairn






Re: .NET Compact Framework using hidden controls in the form

KarenV

Thanks for more clarification, but this seems to be a very poorly thought out solution.

In Windows Mobile 5 at least, we were able to take a press of the "R" for example and also figure out that it's a "5".

This worked great for contact searches where the user doesn't need to think R or 5, just press the button.

In Windows Mobile 6, this functionality is completely gone now from the Contacts application. i.e. pressing a R/5 will search for the R, not also a '5' anymore. This great user experience has been taken away.

I for the life of me can't figure out why MS didn't add an API that takes in a key, and lets the application query like "Are there any other keys/numbers associated with this keypress "

This all seems like a real hack, after seeing the mess in WM5, I would have expected this to be cleaned up.





Re: .NET Compact Framework using hidden controls in the form

mohasad

hi alex,
since i dont have any devices , i have come into one more issue that ,what will be the format of the names of the keys in the registry , i.e. it will be as '1','2','3', or as hexa decimal value such as '31','32','33','34' etc or in the ascii type as '47','48','49' etc.................

thanks
sadiq