在显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题 [英] Having trouble showing and hiding the Windows 10 On Screen Keyboard (osk.exe)

查看:1087
本文介绍了在显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试让屏幕键盘(osk.exe)从我的应用程序出现在Windows 10上(或消失).我的应用程序在Windows 7中运行良好.在osk.exe上调用ShellExecute()会显示那里的键盘,但是在Windows 10中尝试获得相同的行为却很痛苦.

I have been trying to get the onscreen keyboard (osk.exe) to appear (and disappear) on Windows 10 from within my app. My app was running fine in windows 7. Calling ShellExecute() on osk.exe would show the keyboard there but trying to get the same behaviour in Windows 10 has proved to be a pain.

要尝试隐藏键盘,一旦它可见,我就尝试了以下操作:

To try to hide the keyboard, once it is visible, I tried this:

HANDLE wHandle = FindWindowW(L"OSKMainClass", L"On-Screen Keyboard");
if (wHandle != NULL)
{
    long style = GetWindowLong(wHandle, GWL_STYLE);
    if (style & WS_VISIBLE)
    {
        return TRUE;
    }
    else
    {
        SetWindowLongPtr(wHandle, GWL_STYLE, WS_VISIBLE);
    }

但是没有效果.

我还尝试使用 TabTip键盘,但是无法检测到何时可见(我可以检测到何时不可见,但是当它可见时却无法获取它的句柄!).

I also tried using the TabTip keyboard but was unable to detect when it is visible (I can detect when it's not visible but I can't get a handle to it when it is visible!).

任何有关此问题的帮助将不胜感激.

Any help with this problem would be appreciated.

更新:最初未显示osk的原因是'nCmdShow parameter supplied to ShellExecute`,原始代码为此值提供了NULL,并且在Windows 7上运行良好,因此我认为问题出在其他软件上.将其从NULL更改为SW_SHOWNORMAL可以解决出现键盘的问题.

Update: The reason osk wasn't initially been shown was the 'nCmdShowparameter supplied toShellExecute`, the original code supplied NULL for this value and it was working fine on Windows 7 so I had assumed the problem lay elseware. changing it from NULL to SW_SHOWNORMAL fixed the issue with the keyboard appearing.

Paul Sanders的评论:在32位应用程序中,您还必须做一件事,请参见: https://stackoverflow .com/a/50510526/5743288 .

Comment by Paul Sanders: In a 32 bit app you have to do one more thing, see, see: https://stackoverflow.com/a/50510526/5743288.

推荐答案

我决定重写此答案,因为原始内容包含许多不相关的细节,其中大多数是错误的.既然我已经正确理解了这一切实际上是如何工作的,那么要说的话就少得多了,说的话应该对将来的访问者有用得多.

I have decided to rewrite this answer, because the original contained a lot of irrelevant details, most of which were wrong. Now that I understand properly how it all actually works there's a lot less to say, and what there is to say should be a lot more useful to future visitors.

首先,OP的问题的答案是此处.那应该让他完全按照自己的意愿去做.感谢@ zett42指出WM_SYSCOMMAND技巧.现在来看看有趣的东西.

First up, the answer to the OP's question is here. That should let him do exactly what he wants to do. Kudos to @zett42 for pointing out the WM_SYSCOMMAND trick. Now for the interesting stuff.

问题1:为什么在OP中尝试调用ShowWindow()时在osk主窗口中发布WM_SYSCOMMAND消息无效?

Question 1: why does posting a WM_SYSCOMMAND message to osks main window work when calling ShowWindow(), as the OP was trying to do, does not?

答案:好吧,撇开隐藏OSK而不是关闭或最小化OSK的事实来看,这可能不是一个好主意,答案在于称为UI Privilege Level Isolation(UIPI)的东西. OSK运行时升高,这限制了常规应用程序对其进行操作的方式.您可以阅读有关UIPI的更多信息此处.

Answer: Well, putting aside the fact that hiding the OSK rather than closing or minimising it is probably not a good idea anyway, the answer lies in something called UI Privilege Level Isolation (UIPI). OSK runs elevated and this limits the ways it can be manipulated by a regular app. You can read more about UIPI here.

供以后参考,您可以使用SysInternals的流程浏览器.如果您在流程属性"窗口的安全性"选项卡中查找,则对于OSK,您将看到:

For future reference, you can figure out if a program is running elevated using SysInternals' Process Explorer. If you look in the Security tab of the Process Properties window, then for OSK you see:

标记:完整性组:强制性标签\ 强制性标签

Flags: Integrity Group: Mandatory Label\ High Mandatory Label

在(例如)设置"应用中,您会看到:

while for (e.g.) the Settings app, you see:

标记:完整性组:强制性标签\ 强制性标签

Flags: Integrity Group: Mandatory Label\ Medium Mandatory Label

问题2:是否其中任何一个都受OSK是UWP应用的事实影响(请参阅下面@IInspectable的评论)?

Question 2: Is any of this affected by the fact that OSK is a UWP app (see comments below by @IInspectable)?

答案:其实没有.尽管Microsoft 不希望您依靠它,但UWP应用程序的顶级HWND似乎只是普通的HWND. .您可以使用使用64位版本,大声笑).

Answer: Actually, no. The top-level HWND's of UWP apps appear to be just regular HWND's, although Microsoft don't want you to rely on that. You can investigate the exact window hierarchy they use - what there is of it - with Spy++ (and use the 64 bit version, lol).

除:

  1. OP,请尝试编写更好的问题.这是一团糟,已经造成了很多麻烦.我已通过示例方式对您的问题进行了编辑,并为以后的访问者整理了问题,请看一看.并请投票给我.我已经赚了.

  1. OP, please try to write better questions. This one was a mess and it has caused a lot of trouble. I have edited your question by way of example and to clean it up for future visitors, please take a look. And please vote me up. I have earned it.

人们发布的回复:请先做一些研究.此线程中的其他答案没有用,部分原因(我将是第一个承认),因为问题的措词最初是这样.我本人在最初的评论中就犯了这个错误,所以我们都可以从中学到东西.

People posting replies: please do a bit of research first. The other answers in this thread are not useful, partly (I would be the first to admit) because of the way the question was originally worded. I myself made this mistake in my initial comments so we can all learn from this.

这篇关于在显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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