2

I have a C# winForms application that makes use of the Windows 8 keyboard.

I open the keyboard by launching tabtip.exe.

I am able to close the keyboard using a PostMessage command like this:

public static void HideOnScreenKeyboard()
{
    uint WM_SYSCOMMAND = 274;
    uint SC_CLOSE = 61536;
    IntPtr KeyboardWnd = FindWindow("IPTip_Main_Window", null);
    PostMessage(KeyboardWnd.ToInt32(), WM_SYSCOMMAND, (int)SC_CLOSE, 0);
}

I think using PostMessage it should be possible to simulate almost anything programmatically if you just pass the correct values.

The values used for closing the keyboard (274 and 61536) I just found on the internet.

It looks that it is possible to grab these values using Spy++, or some other tools but I am unable how to do this.

Can anybody tell me the values needed to simulate a press on the &123 key, so the keyboard switches to the numeric keyboard?

Or, does anybody know how to get these values?

I have tried Spy++, but so many messages are passing constantly that I don't know where to look.

Look at the image of the OnScreenKeyboard to see what key I mean

Tabtip keyboard &123

2 Answers 2

3

You could try to use SendInput to simulate a mouse click event on the &123 button of the virtual keyboard window.

Below is an example of how to use SendInput to send a mouse click (left_down + left_up) to the button but I haven't included the code to programatically find the window and get the window size.

[StructLayout(LayoutKind.Sequential)]
public struct MINPUT
{
  internal uint type;
  internal short dx;
  internal short dy;
  internal ushort mouseData;
  internal ushort dwFlags;
  internal ushort time;
  internal IntPtr dwExtraInfo;
  internal static int Size
  {
     get { return Marshal.SizeOf(typeof(INPUT)); }
  }
}      

const ushort MOUSEEVENTF_ABSOLUTE = 0x8000;
const ushort MOUSEEVENTF_LEFTDOWN = 0x0002;
const ushort MOUSEEVENTF_LEFTUP = 0x0004;

// programatically determine the position and size of the TabTip window
// compute the location of the center of the &123 key
int coordinateX = ...
int coordinateY = ...

var pInputs = new[] { 
                new MINPUT() {
                     type = 0×01; //INPUT_KEYBOARD                         
                     dx = coordinateX,
                     dy = coordinateY;
                     dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
                     time = 0;
                     dwExtraInfo = IntPtr.Zero;
                },
                new MINPUT() {
                     type = 0×01; //INPUT_KEYBOARD
                     dx = coordinateX,
                     dy = coordinateY;
                     dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP;
                     time = 0;
                     dwExtraInfo = IntPtr.Zero;
               }
};

SendInput((uint)pInputs.Length, pInputs, MINPUT.Size);
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Miky, I don't think this is answer to my question. On Windows 8 when you run TabTip.exe an On Screen Keyboard pops up. This has a &123 key I want to press. I added an image to my original questions to make the question more clear.
You're right.. it seems I misunderstood your question
How about using a mouse event instead. You can use SendInput to simulate a mouse click and determine the coordinates of the &123 key programatically, based on the location of the TabTip window..
This does work but not really the desired effect. Now the keyboard pops in alphanumeric, and then I simulate the mousepress and then the keyboard switches to numeric. So the user can see the swapping. Not really desired. But that would be the same with how I wanted to solve it so your answer is valid. I will just drop this from my app, so the users must manually switch to numeric keyboard if desired.
0

Why don't you set the input scope of the edit control to numeric? New built-in edit controls with the correct properties automatically trigger the numeric mode when touched.

Rather than hacking the Touch Input Panel which appears differently in different locales, etc. set InputScope of the text box to Number and let Windows do the magic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.