gpt4 book ai didi

windows-8 - 在 Windows 8 上以编程方式显示/隐藏键盘

转载 作者:行者123 更新时间:2023-12-02 19:24:25 26 4
gpt4 key购买 nike

我正在尝试以编程方式在 Windows Metro 应用程序上显示/隐藏键盘。我最初认为我可以使用折叠的文本框并将焦点放在它上面来做到这一点。但似乎在这个 link 中不允许这样做。该链接还讨论了 AutomationPeer 和 TextAutomationPeer 来完成此操作。有关于如何使用这些的资源吗?

提前致谢PK

最佳答案

来自here :

UI Automation is the mechanism through which developers communicate whether or not a particular UI element can receive text input. You must ensure that the appropriate accessibility properties are set in your apps so that the touch keyboard will know to appear when focus lands on a specific UI element. For Windows-provided controls, this will be done automatically because proper accessibility properties are set by default, but for custom controls and experiences you must do additional work to set the accessibility properties correctly; remember that the touch keyboard reacts to these properties.

If you use C# or C++, use an AutomationPeer object, and specifically a TextAutomationPeer. A Windows 8 Release Preview sample will demonstrate how to do this in C#. Remember that the control must also be editable and able to receive text to get the keyboard to invoke, in addition to having the appropriate accessibility settings. Indicating that something can receive text when it cannot will mislead accessibility tools and the users who rely on them.

To enable user-driven invocation, we track the coordinates of the last touch event and compare them to the location of the bounding rectangle of the element that currently has focus. If the point is contained within the bounding rectangle, the touch keyboard is invoked.

因此您无法以编程方式显示键盘。隐藏/显示键盘的适当方法是将控件设置为使用 AutomationPeer 对象接受输入。

来自here ,如果您将输入控件设置为只读,那么它将不会触发键盘,因此您可能可以使用它来控制键盘何时打开。

编辑:

实现文本自动化对等点时需要检查一些事项:

  1. 确保使用真实的触摸设备进行测试,或者使用带有基本触摸模式工具的模拟器进行测试。如果您不这样做,自动化对等点将不会激活,因为它只能通过手写笔或触摸输入(而不是鼠标)激活。

  2. 确保您的自定义控件实现 OnCreateAutomationPeer 如下所示:

    protected 覆盖 AutomationPeer OnCreateAutomationPeer(){ 返回新的 CustomControl2AutomationPeer(this);}

  3. 确保您的 Automation Peer 实现 FrameworkElementAutomationPeerITextProviderIValueProvider

在示例 here 中找到更多详细信息.

关于windows-8 - 在 Windows 8 上以编程方式显示/隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10129550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com