Show & hiding the Windows 8 on screen keyboard fro

2019-01-11 13:59发布

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

8条回答
三岁会撩人
2楼-- · 2019-01-11 14:26

try this one

System.Diagnostics.Process.Start("TabTip.exe");

I hope this will help you.

查看更多
【Aperson】
3楼-- · 2019-01-11 14:29

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.

查看更多
做个烂人
4楼-- · 2019-01-11 14:31

Well I would try something like this

Process myProcess = Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
myProcess.CloseMainWindow();
myProcess.Close();
查看更多
做个烂人
5楼-- · 2019-01-11 14:32

Maybe you can try the solution published on this blog: http://mheironimus.blogspot.nl/2015/05/adding-touch-keyboard-support-to-wpf.html

It contains some of the things you asked for (and more):

  • Show and hide keyboard
  • Move focus using FrameworkElement.BringIntoView ()
  • FrameworkElement.InputScope property to choose which keyboard layout to show (numeric, email, url, etc)
查看更多
Explosion°爆炸
6楼-- · 2019-01-11 14:33

This should work to open, then kill the process.

Process proc = Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
proc.Kill();

Killing the process will close it.

If you debug and step through these two lines, however, the same error you mentioned above occurs - "Process has exited, so the request information is not available."

If you aren't stepping through these two lines while debugging, no exception is thrown and the on-screen keyboard will be killed.

If you use CloseMainWindow() the keyboard will not close. CloseMainWindow() is for processes with a UI, so you would think it would be effective on this, but perhaps because the keyboard is part of the OS it doesn't count.

Confirm that it works, then throw the proc.Kill() in a try-catch with error logging for peace of mind.

查看更多
手持菜刀,她持情操
7楼-- · 2019-01-11 14:38

I am not sure how to hide the keyboard programmatically, but just as you know I just recently published a sample on how to trigger (as-in, show) the touch keyboard in WPF applications when a user clicks into a Textbox, its here:

http://code.msdn.microsoft.com/Enabling-Windows-8-Touch-7fb4e6de

The cool thing about this sample, as it doesn't require the use of Process and instead uses supported Windows 8 API to trigger the touch keyboard for TextBox controls using automation.

It has been something I've been working on for many months, i'm glad to finally contribute this example to our community. Please let me know if there are any questions, suggestions, problems, etc in the sample Q&A pane

查看更多
登录 后发表回答