Show & hiding the Windows 8 on screen keyboard from WPF

Sun picture Sun · Jun 13, 2013 · Viewed 20.7k times · Source

I'm writing a WPF application for a Windows 8 tablet. It's full windows 8 and not ARM/RT.

When the user enters a textbox I show the on screen keyboard using the following code:

System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");

This works fine however I don't know how to hide the keyboard again?

Anybody know how to do this?

Also, is there any way I can resize my application so that focused control is moved up when the keyboard appears? A bit like it does for a windows RT application.

Many Thanks

Answer

tasasaki picture tasasaki · Mar 14, 2014

I could successfully close onscreen keyboard with the following C# code.

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName,string lpWindowName);

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;

private void closeOnscreenKeyboard()
{
    // retrieve the handler of the window  
    int iHandle = FindWindow("IPTIP_Main_Window", "");
    if (iHandle > 0)
    {
        // close the window using API        
        SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
    }  
}

private void Some_Event_Happened(object sender, EventArgs e)
{
    // It's time to close the onscreen keyboard.
    closeOnscreenKeyboard();
}

I hope this will help you.