且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#WinForms中使用Windows屏幕键盘

更新时间:2023-12-05 17:37:46

我现在使用以下命令启动触摸键盘,而不是屏幕键盘(无论如何我都希望在Windows 8上使用该键盘):

I am now launching the "Touch Keyboard" as opposed to the "On-Screen Keyboard" (which is the keyboard I wanted on Windows 8 anyway) with:

string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
string keyboardPath = Path.Combine(progFiles, "TabTip.exe");

this.keyboardProc = Process.Start(keyboardPath);

这在我的Win7和Win8上都可以使用,无论我的64位OS上的32位应用程序如何。但是,完成后,我仍然存在以编程方式关闭键盘的问题。进程 this.keyboardProc 似乎没有得到处理,并立即具有属性 HasExited = true

This works on my Win7 and Win8, regardless of my 32-bit app on 64-bit OS. However, I still have the problem of programmatically closing the keyboard when I'm done. The process, this.keyboardProc, does not seem to get the handle, and immediately has property HasExited = true. This means my attempts to close or kill it fail.

根据此线程,如果用户手动打开键盘(或以编程方式启动它),则键盘不会当文本字段失去焦点时自动关闭/隐藏: Windows 8-如何取消触摸键盘?我尝试过将焦点设置为隐藏按钮的解决方法,但是由于我自己启动了键盘,因此它不会自动关闭。

According to this thread, if the user manually opens the keyboard (or I programmatically launch it), the keyboard will not automatically close/hide when the text field loses focus: Windows 8 - How to Dismiss Touch Keyboard? I tried the workaround of setting the focus to a hidden button, but since I launched the keyboard myself, it doesn't close automatically.