在WinForms输入焦点上自动弹出平板电脑触摸键盘 [英] Automatically pop up tablet touch keyboard on WinForms input focus

查看:605
本文介绍了在WinForms输入焦点上自动弹出平板电脑触摸键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Windows 10上的


这只是Visual Studio创建的默认Windows Forms Application C#项目。没有添加代码,没有属性更改。通过从 Toolbox 中删除(同样未更改任何属性),仅添加了 TextBox

  this.textBox1 = new System.Windows.Forms.TextBox(); 
this.textBox1.Location = new System.Drawing.Point(64,27);
this.textBox1.Name = textBox1;
this.textBox1.Size = new System.Drawing.Size(100,20);
this.textBox1.TabIndex = 0;




为了验证我的假设,弹出窗口应该是自动的:



  • 我尝试在Windows 10上运行Windows XP版本的 notepad.exe 。它会自动弹出触摸键盘。我怀疑Windows XP是否对触摸键盘有任何明确的支持。



  • 我还尝试了一些古老的MFC应用程序(例如FileZilla 2.2。 2005年15月)。它还会在所有输入框中弹出触摸键盘。同样,我很确定,MFC也没有明确支持触摸键盘。



  • 对于基于wxWidgets构建的应用程序(对于例如FileZilla 3.x)。






WinForms似乎有问题阻止自动弹出。有趣的是,自动弹出的工作原理是:



  • 用于(可编辑)组合框( ComboBox DropDownStyle = DropDown

  • 用于密码模式下的文本框( TextBox.PasswordChar

  • 用于富文本框( RichTextBox

  • 当输入框在当前硬件键盘处于焦点时具有焦点已删除 (我通过在Lenovo Yoga笔记本上翻转屏幕来测试这一点),但此后再也没有。




我已经看过所有通过运行 TabTip.exe 来提示显式弹出。例如:



大多数解决方案提供这样的代码:

  var progFiles = @" C:\Program Files\Common Files\  Microsoft Sharedink; 
var keyboardPath = Path.Combine(progFiles, TabTip.exe);
this.keyboardProc = Process.Start(keyboardPath);

但我不敢相信这可能是官方办法。如果没有别的,那就是因为没有一种干净的方法可以隐藏通过运行 TabTip.exe 打开的键盘(解决方案包括杀死进程或发送 Esc 键)。


实际上,上述破解似乎在Windows 10周年更新中不再起作用:





有趣的是,我看到与Delphi / C ++ Builder / VCL应用程序相同的行为。键盘不会弹出编辑框( TEdit )。确实会弹出组合框( TComboBox )和密码模式下的编辑框( PasswordChar )。有趣的是,对于 TRichEdit ,与.NET RichTextBox 的显着区别是,可能值得研究。


(未回答)这个问题描述了一个相同的问题行为:

在编辑框键盘中编写的Delphi XE8 touch应用程序在Windows 10中未出现键盘。 / p>

解决方案

Ofek的提示Shilon的答案,看来触摸键盘可以利用 UI自动化






一个人可以使用 UIAutomationClient.dll 。



用于将UI自动化神奇地注入到应用程序中然后,必须触发程序集内部类 UiaCoreApi 的类初始化程序。



On可以通过以下方式实现呼叫似乎没有操作:

  AutomationElement.FromHandle(IntPtr)(-1)






另一种方法是显式实现自动化UI。为此,请实现 ITextProvider / 分别用于输入控件的 IValueProvider 接口。



绑定接口的实现控件,处理 WM_GETOBJECT 窗口消息,其中 lParam = RootObjectId



有关实现的示例,请参见








尽管有趣的是,触摸键盘可以直接使用的控件(如组合框或密码编辑框,请参见答案),不要实现 WM_GETOBJECT / RootObjectId 。他们后面必须有其他机器。


When I run a WinForms (or Delphi, see at the end) application on Windows 10 in a tablet mode, a touch keyboard does not pop up automatically, when an input box is focused.

I believe that this should happen automatically, without any additional code/setup.


For a test, I have the simplest VS 2015 WinForms desktop application with a single TextBox control.

It's simply the default Windows Forms Application C# project as created by Visual Studio. No code added, no properties changed. Just the TextBox was added, by dropping from the Toolbox (again no properties changed):

this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.Location = new System.Drawing.Point(64, 27);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;


To verify my assumption that the pop up should be automatic:

  • I've tried to run Windows XP version of notepad.exe on Windows 10. It automatically pops up the touch keyboard. I doubt the Windows XP had any explicit support for touch keyboards.

  • I've also tried some ancient MFC applications (for example FileZilla 2.2.15 from 2005). It also pops up the touch keyboard on all its input boxes. Again, I'm pretty sure, the MFC had no explicit support for touch keyboards either.

  • The same for applications built on wxWidgets (for example FileZilla 3.x).


It looks like there's something broken in WinForms that prevents the automatic popup. Interestingly, the automatic pop up works:

  • for (editable) combo boxes (ComboBox with DropDownStyle = DropDown)
  • for text boxes in a password mode (TextBox.PasswordChar)
  • for rich text boxes (RichTextBox)
  • when the input box has focus at the moment the hardware keyboard is "removed" (I test this by flipping the screen on Lenovo Yoga notebook), but never after.

I've seen all the hints about an explicit popup by running the TabTip.exe. E.g.:

Most of the "solutions" offer a code like this:

var progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
var keyboardPath = Path.Combine(progFiles, "TabTip.exe");
this.keyboardProc = Process.Start(keyboardPath);

But I cannot believe this could be the "official" way. If for nothing else, then because there's no clean way to hide the keyboard opened by running the TabTip.exe (solutions include hacks like killing the process or sending Esc key).

And actually the above hack does not seem to work anymore in Windows 10 Anniversary Update:


Interestingly, I see the same behavior with Delphi/C++ Builder/VCL applications. The keyboard does not pop up for edit boxes (TEdit). It does pop up for combo boxes (TComboBox) and for edit boxes in a password mode (PasswordChar). Interestingly not for TRichEdit, what is notable difference to .NET RichTextBox, that maybe worth investigating.

This (unanswered) question describes an identical behavior:
Application written Delphi XE8 touch in edit boxes keyboard not appear in Windows 10.

解决方案

As hinted by Ofek Shilon's answer, it seems that the touch keyboard can leverage the UI automation.


One can use implementation of UI automation from UIAutomationClient.dll.

For the UI automation to be magically injected into an application, class initializer of the assembly internal class UiaCoreApi have to be triggered.

On can achieve that for example by calling seeming no-op:

AutomationElement.FromHandle(IntPtr)(-1)


Another way is to implement automation UI explicitly. For that implement the ITextProvider/IValueProvider interfaces for the respective input control.

To bind the implementation of the interfaces to the control, handle WM_GETOBJECT window message with lParam = RootObjectId.

For an example of implementation, see


Though interestingly, controls, for which touch keyboard works out-of-the-box (like combo box or password edit box, see the answer), do not implement the WM_GETOBJECT/RootObjectId. There must be a different machinery behind them.

这篇关于在WinForms输入焦点上自动弹出平板电脑触摸键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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