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

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

问题描述


  • VS 2010

  • 开发在64位操作系统(Windows 7,Windows 8-桌面应用)上运行的32位应用

  • C#

  • .NET 4.0

  • WinForms

  • VS 2010
  • Developing 32-bit app that runs on 64-bit OS (Windows 7, Windows 8 - desktop app)
  • 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 失败,并显示找不到指定的路径。 对于 system32 osk.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发表):< a href = http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/10ebc62f-e6d7-4072-9fd1-ea3784a0966f/ rel = nofollow noreferrer> http:// social。 msdn.microsoft.com/Forums/zh-CN/netfx64bit/thread/10ebc62f-e6d7-4072-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)下,键盘未在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 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.

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

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