如何在 C# WinForms 中使用 Windows 屏幕键盘 [英] How to use Windows On-Screen Keyboard in C# WinForms

查看:32
本文介绍了如何在 C# WinForms 中使用 Windows 屏幕键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • VS 2010
  • 开发在 64 位操作系统(Windows 7、Windows 8 - 桌面应用)上运行的 32 位应用
  • C#
  • .NET 4.0
  • WinForms

我发现有很多关于从应用程序启动 Windows 屏幕键盘 (osk.exe) 的线程,但我遇到了一些问题.似乎是因为我在 64 位操作系统上运行 32 位应用程序.我在这里尝试了 WooCaSh 发布的代码:WinForms 中屏幕上的键盘

I have found many threads on launching the Windows on-screen keyboard (osk.exe) from an application, but I am running into some problems. It appears to be because I am running a 32-bit app on a 64-bit OS. I've tried the code posted by WooCaSh here: Keyboard on the screen in WinForms

但是这三种不同的路径都不适合我.对于 sysnative 路径,Process.Start 失败并显示 找不到指定的路径." 对于 system32osk.exe 路径,我收到无法启动屏幕键盘" 错误对话框.

But none of the three different paths work for me. For the sysnative path, Process.Start fails with "Cannot find the path specified." For the system32 and osk.exe paths, I get the "Could not start the on-screen keyboard" error dialog.

我在这里找到了一个可能的解决方法,它比我想要的要复杂一些(由 eryang 发布):http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/10ebc62f-4072d-9fd1-ea3784a0966f/

I found a possible workaround here, which is a little more complicated than what I was looking for (post by eryang): http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/10ebc62f-e6d7-4072-9fd1-ea3784a0966f/

  1. 有没有更简单或更正确的方法来做到这一点?
  2. 我希望在平板电脑上运行我的应用程序会在用户选择文本框时自动启动屏幕键盘,但没有运气.这是正常的还是我错过了什么?我发现在桌面模式下(我的应用程序是这样)键盘不会在 Windows 8 中自动启动:http://www.bleepingcomputer.com/forums/t/480250/keyboard-does-not-pop-up-automatically/ 显然它适用于 Windows 7 平板电脑,但我无法测试,因为我这里只有 Windows 8 平板电脑.
  1. Is there an easier or correct way to do this?
  2. I was hoping that running my app on a tablet would automatically launch the on-screen keyboard when the user selects a textbox, but no luck. Is this normal or am I missing something? I've found that the keyboard is not automatically launched in Windows 8 when in Desktop mode (which my app is): http://www.bleepingcomputer.com/forums/t/480250/keyboard-does-not-pop-up-automatically/ Apparently it works on Windows 7 tablets, but I can't test because I only have Windows 8 tablets here.

推荐答案

我现在推出触摸键盘",而不是屏幕键盘"(无论如何,这是我在 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 FilesCommon FilesMicrosoft Sharedink";
string keyboardPath = Path.Combine(progFiles, "TabTip.exe");

this.keyboardProc = Process.Start(keyboardPath);

这适用于我的 Win7 和 Win8,无论我在 64 位操作系统上的 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.

这篇关于如何在 C# WinForms 中使用 Windows 屏幕键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆