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

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

问题描述


  • VS 2010

  • 开发32位应用程序在64位操作系统上运行(Win7的,Win8的 - 桌面应用程序)

  • C#

  • .NET 4.0

  • 的WinForms



我已经找到关于开展从应用程序在Windows屏幕键盘(osk.exe)很多线程,但我遇到了一些问题。这似乎是因为我在64位操作系统上运行32位应用程序。我已经试过张贴WooCaSh这里的代码:屏幕上
键盘的WinForms



但没有这三个不同的路径为我工作。对于sysnative路径的Process.Start找不到指定的路径。对于SYSTEM32和osk.exe路径,我得到无法启动屏幕上的键盘错误对话框。



我发现了一个可能的解决方法在这里,这是一个的 http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/10ebc62f-e6d7-4072-9fd1-ea3784a0966f/




  1. 是否有更简单的或正确的方式做到这一点?

  2. 我希望运行我的应用程序在平板电脑上会自动启动,当用户选择一个文本框,屏幕上的键盘,但没有运气。这是正常的还是我失去了一些东西? 修改:发现这个键盘不会自动在Win8的桌面模式(这我的应用程序)时推出:的 http://www.bleepingcomputer.com/forums/t/480250/keyboard-does-not-pop-up-automatically/ 显然,它可以在Win7的平板电脑,但我不能测试,因为我只有Win8的平板电脑在这里。


解决方案

我现在正在开展触感键盘,而不是在屏幕键盘(这是我想在Windows 8键盘反正)有:

 字符串progFiles = @C:\Program Files\Common Files\Microsoft Shared\ink 
串keyboardPath = Path.Combine(progFilesTabTip.exe);

this.keyboardProc =的Process.Start(keyboardPath);

这适用于我的Win7和Win8的,不管我的32位应用程序在64位操作系统。不过,我仍然有编程关闭键盘时,我做的问题。这个过程中,this.keyboardProc,似乎并没有得到处理,并立即拥有财产HasExited =真。这意味着我将尝试关闭或杀死它失败。



根据这一线索,如果用户手动打开键盘(或以编程方式启动它),键盘不会自动关闭/隐藏当文本字段失去焦点: Windows 8的 - 如何辞退触摸键盘?我试着焦点设置到一个隐藏按钮的解决办法,但自从我推出了自己的键盘,它不会自动关闭。


  • VS 2010
  • Developing 32-bit App that runs on 64-bit OS (Win7, Win8 - desktop app)
  • C#
  • .NET 4.0
  • WinForms

I have found many threads on launching the Windows on-screen keyboard (osk.exe) from an application, but 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

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

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. 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? EDIT: Found that the keyboard is not automatically launched in Win8 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 Win7 tablets, but I can't test because I only have Win8 tablets here.

解决方案

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);

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.

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.

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

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