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

编程入门 行业动态 更新时间:2024-10-11 23:22:06
本文介绍了如何在 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 失败并显示 找不到指定的路径." 对于 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 发布):social.msdn.microsoft/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): social.msdn.microsoft/Forums/en-US/netfx64bit/thread/10ebc62f-e6d7-4072-9fd1-ea3784a0966f/

  • 有没有更简单或更正确的方法来做到这一点?
  • 我希望在平板电脑上运行我的应用程序会在用户选择文本框时自动启动屏幕键盘,但没有运气.这是正常的还是我错过了什么?我发现在桌面模式下(我的应用程序是这样)键盘不会在 Windows 8 中自动启动:www.bleepingcomputer/forums/t/480250/keyboard-does-not-pop-up-automatically/ 显然它适用于 Windows 7 平板电脑,但我无法测试,因为我这里只有 Windows 8 平板电脑.
  • Is there an easier or correct way to do this?
  • 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): www.bleepingcomputer/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 屏幕键盘

    本文发布于:2023-11-06 03:46:40,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1562643.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:屏幕   键盘   如何在   Windows   WinForms

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!