views:

3341

answers:

4

Hi,

In the application there is a dialog where only numeric string entries are valid. Therefore I would like to set the numeric keyboard layout.

Does anyone know how to simulate key press on the keyboard or any other method to change the keyboard layout?

Thanks!

A: 

You can use the InputModeEditor:

InputModeEditor.SetInputMode(textBox1,InputMode.Numeric);
kgiannakakis
it's a native code application so it can't be done this way.
niko
+2  A: 

You don't need to.

Just like full windows, you can set the edit control to be numeric input only. You can either do it manually or in the dialog editor in the properites for the edit control.

The SIP should automatically display the numeric keyboard when the numeric only edit control goes into focus.

Shane Powell
A: 

There is only one way to do this (edit: this is referring to the SIP in non-smartphone Windows Mobile, so I'm not sure it's relevant to your question), and it does involve simulating a mouse click on the 123 button. This is only half the problem, however, since you also need to know whether the keyboard is already in numeric mode or not. The way to do this is to peek a pixel near the upper left corner of the keypad - if you look at how the 123 button works, you'll see that it's system text on windows background, and then inverted in numeric mode (so the pixel will be the system text color only when in numeric mode). There's one more bit of weirdness you have to do to guarantee it will work on all devices (you have to draw a pixel on the keyboard, too).

Lucky for you, I have an easy-to-use code sample that does all this. Unlucky for you, it's in C#, but I think it should at least point you in the right direction.

MusiGenesis
A: 

Hey MusiGenesis, can you share the C# code abot figuring out the keypad on the screen. I want to pull up a numeric keypad when a text box is selected using C# for windows mobile.

Gopish