Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WPF

Virtual Keyboard (TabTip) Integration in WPF on Win 8.1 and Win 10

5.00/5 (3 votes)
23 Aug 2016CPOL 67.3K  
Virtual Keyboard (TabTip) integration in WPF on Win 8.1 and Win 10

Introduction

I open-sourced my project to automate everything concerning TabTip integration in WPF app.

Simple to use

The easiest way to install the WPFTabTip is using the Package Manager Console in Visual Studio:

C#
PM> Install-Package WPFTabTip

One line of code in your startup logic, and you are good to go!

C#
TabTipAutomation.BindTo<TextBox>();

You can bind TabTip automation logic to any UIElement. Virtual Keyboard will open when any such element 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.

Hardware Keyboard Detection

By default, TabTip automation will occur only if no hardware keyboard is detected.

You can change that behavior by setting TabTipAutomation.IgnoreHardwareKeyboard to any of the following values:

C#
public enum HardwareKeyboardIgnoreOptions
    {
        /// <summary>
        /// Do not ignore any keyboard.
        /// </summary>
        DoNotIgnore,

        /// <summary>
        /// Ignore keyboard, if there is only one, and it's description 
        /// can be found in ListOfHardwareKeyboardsToIgnoreIfSingleInstance.
        /// </summary>
        IgnoreIfSingleInstanceOnList,

        /// <summary>
        /// Ignore keyboard, if there is only one.
        /// </summary>
        IgnoreIfSingleInstance,

        /// <summary>
        /// Ignore all keyboards
        /// </summary>
        IgnoreAll
    }

If you want to ignore specific keyboard, you should set TabTipAutomation.IgnoreHardwareKeyboard to IgnoreIfSingleInstanceOnList, and add keyboard description to TabTipAutomation.ListOfHardwareKeyboardsToIgnoreIfSingleInstance.

To get description of keyboards connected to machine, you can use the following code:

C#
new ManagementObjectSearcher(new SelectQuery("Win32_Keyboard")).Get()
                .Cast<ManagementBaseObject>()
                .SelectMany(keyboard =>
                    keyboard.Properties
                        .Cast<PropertyData>()
                        .Where(k => k.Name == "Description")
                        .Select(k => k.Value as string))
                .ToList();

Change Keyboard Layout

To specify keyboard layout to be used with certain element, you can set InputScope property in XAML to one of the following:

  • Default
  • Url
  • EmailSmtpAddress
  • Number

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)