Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make WPF input control show virtual Keyboard when it got focus in touch screen

People also ask

How do I make my virtual keyboard appear?

Go to Start , then select Settings > Accessibility > Keyboard, and turn on the On-Screen Keyboard toggle. A keyboard that can be used to move around the screen and enter text will appear on the screen. The keyboard will remain on the screen until you close it.

How do I make the touchscreen keyboard appear?

To open the touch keyboard Here's how: Select Start > Settings >Personalization > Taskbar > Taskbar corner icons, then make sure Touch keyboard is turned on.

Is a touch screen with virtual keyboard?

An alternative to a physical keyboard, a virtual keyboard is a software-based keyboard used with touch screen devices. The keyboard is a digital representation of a QWERTY keyboard that appears on the screen when text input is required by the application.


Try this,

First check for a physical keyboard presence:

KeyboardCapabilities keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities();
return  keyboardCapabilities.KeyboardPresent != 0 ? true : false;

If you do not find a physical keyboard, use the in-built virtual keyboard of windows:

Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + "osk.exe");

Got help from here: link 1 link 2


I've published a sample on how to trigger the touch keyboard in WPF applications when a user clicks into a Textbox, its here:

http://code.msdn.microsoft.com/Enabling-Windows-8-Touch-7fb4e6de

It has been something I've been working on for many months, i'm glad to finally contribute this example to our community. Please let me know if there are any questions, suggestions, problems, etc in the sample Q&A pane


I created a library to automate everything concerning TabTip integration in WPF app.

You can get it on nuget, and after that all you need is a simple config in your apps startup logic:

TabTipAutomation.BindTo<TextBox>();

You can bind TabTip automation logic to any UIElement. Virtual Keyboard will open when any element of specified type will get focus, and it will close when element will lose focus. Not only that, but TabTipAutomation will move UIElement (or Window) into view, so that TabTip will not block focused element.

For more info refer to the project site.


This solution is very simple: http://code.msdn.microsoft.com/windowsapps/Enabling-Windows-8-Touch-7fb4e6de

The steps are detailed in the link above, here is the short version:

  • Add a UIAutomationClient reference
  • Use IFrameworkInputPane from managed code (DLL at link or convert inputpanelconfiguration.idl to DLL, see steps below)
  • Create new class InkInputHelper to disable inking support (code below)
  • Call InkInputHelper.DisableWPFTabletSupport(); from MainWindow constructor or similar
  • Add using System.Windows.Interop;
  • Add to MainWindow_Loaded or similar:

        System.Windows.Automation.AutomationElement asForm =
        System.Windows.Automation.AutomationElement.FromHandle(new WindowInteropHelper(this).Handle);
        InputPanelConfigurationLib.InputPanelConfiguration inputPanelConfig = new InputPanelConfigurationLib.InputPanelConfiguration();
        inputPanelConfig.EnableFocusTracking();
    

To convert inputpanelconfiguration.idl to DLL

On Windows 8.1: c:\Program Files (x86)\Windows Kits\8.1\Include\um\inputpanelconfiguration.idl

To build a DLL from the IDL use the following steps:

  • Start a command prompt
  • Use the MIDL compiler tool to build a Type Library TLB file
    • Example: midl /tbld {filename}
  • Use the TLBIMP tool to convert the above generated Type Library (TLB file) into a DLL that .NET can use by running the following command
    • Example: TLBIMP.exe InputpanelConfiguration.tlb /publickey:{pathToKey} /delaysign

InkInputHelper class:

using System;
using System.Reflection;
using System.Windows.Input;

namespace ModernWPF.Win8TouchKeyboard.Desktop
{
public static class InkInputHelper
{
    public static void DisableWPFTabletSupport()
    {
        // Get a collection of the tablet devices for this window.  
        TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;

        if (devices.Count > 0)
        {
            // Get the Type of InputManager.
            Type inputManagerType = typeof(System.Windows.Input.InputManager);

            // Call the StylusLogic method on the InputManager.Current instance.
            object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                        BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                        null, InputManager.Current, null);

            if (stylusLogic != null)
            {
                //  Get the type of the stylusLogic returned from the call to StylusLogic.
                Type stylusLogicType = stylusLogic.GetType();

                // Loop until there are no more devices to remove.
                while (devices.Count > 0)
                {
                    // Remove the first tablet device in the devices collection.
                    stylusLogicType.InvokeMember("OnTabletRemoved",
                            BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
                            null, stylusLogic, new object[] { (uint)0 });
                }
            }
        }
    }
}
}

This should work. Again, much better info and a downloadable sample in the link. I only copy pasted the basics for archiving purposes.


When targeting .Net 4.6.2+ you don't need to do anything:

https://riptutorial.com/wpf/example/23104/showing-touch-keyboard-on-windows-8-and-windows-10


I saw this done in a TechEd session, you need to first disable Inking support (DisableWPFTabletSupport) then you can create an InputPanelConfiguration (AutomationElement.FromHandle(new WindowsInteropHelper(this).Handle) and call EnableFocusTracking.

DisableWPFTabletSupport: http://msdn.microsoft.com/en-us/library/ee230087.aspx

EnableFocusTracking: http://msdn.microsoft.com/en-us/library/windows/desktop/jj126268(v=vs.85).aspx