Show & hiding the Windows 8 on screen keyboard from WPF

后端 未结 8 1728
我寻月下人不归
我寻月下人不归 2020-12-03 08:17

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 fo

8条回答
  •  春和景丽
    2020-12-03 08:55

    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.

提交回复
热议问题