Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically pop up tablet touch keyboard on WinForms input focus

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.

enter image description here

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.:

  • How to use Windows On-Screen Keyboard in C# WinForms
  • Open and close Windows 8 touch keyboard tabtip under desktop
  • How do I close the on-screen keyboard process from C# winform correctly?
  • Keyboard Winforms on Windows 10 (surface)

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:

  • Show touch keyboard (TabTip.exe) in Windows 10 Anniversary edition

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.

like image 568
Martin Prikryl Avatar asked Mar 23 '16 13:03

Martin Prikryl


People also ask

How do I make my touch keyboard appear automatically?

In most cases, you can tap where you want to enter text and the touch keyboard will open automatically. If it doesn't, you can turn it on yourself. Here's how: Select Start > Settings >Personalization > Taskbar > Taskbar corner icons, then make sure Touch keyboard is turned on.

How do I stop the onscreen keyboard from popping up?

Jan 5, 2022•KnowledgeWhile on the login screen for a Chromebook, select the settings menu from the bottom right. Select Accessibility. Locate the checkbox to toggle the keyboard off.


2 Answers

The root cause seems to be that Winforms' textBox is not an AutomationElement, while the rest of the mentioned controls (ComboBoxes etc) are.

Quoting Markus von und zu Heber's accepted answer here:

We found it in the article "Automatic Touch Keyboard for TextBoxes in WPF Applications on Windows 8+", but it also works very good (and even easier!) for winforms. Thank you, Dmitry Lyalin!

  1. Insert a reference to UIAutomationClient.dll to your project

  2. In the form-load-handler of the application's main window, insert the following code:

    var asForm = System.Windows.Automation.AutomationElement.FromHandle(this.Handle); 
like image 198
Ofek Shilon Avatar answered Sep 29 '22 01:09

Ofek Shilon


I've been down this road a few times and have only ever been able to implement the taptip.exe option. And in turn close the window by killing the process. I also found out that with some registry hacks you can get the keyboard to default to the handwriting panel if you so choose. But then that only works in Win8 and fails in Win10. Here is what I've done in case anyone else finds this useful:

RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\TabletTip\\1.7");  registryKey?.SetValue("KeyboardLayoutPreference", 0, RegistryValueKind.DWord); registryKey?.SetValue("LastUsedModalityWasHandwriting", 1, RegistryValueKind.DWord);  Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe"); 

I need to give credit to this post for the registry idea: Windows 8 Desktop App: Open tabtip.exe to secondary keyboard (for numeric textbox)

like image 27
jaredbaszler Avatar answered Sep 29 '22 03:09

jaredbaszler