Click here to Skip to main content
15,887,436 members
Articles / Desktop Programming / WPF
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
23 Aug 2016CPOL 63.1K   5   29
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)


Written By
Team Leader
Russian Federation Russian Federation
Max Fedotov is currently working in Moscow, Russia.
His set of skills include C#, XAML, Silverlight, WPF as well as Delphi and InterSystems Caché.

Comments and Discussions

 
GeneralRe: how to use Pin
Max Fedotov31-Aug-16 2:20
Max Fedotov31-Aug-16 2:20 
GeneralRe: how to use Pin
Herilane31-Aug-16 2:46
professionalHerilane31-Aug-16 2:46 
GeneralRe: how to use Pin
Max Fedotov31-Aug-16 2:35
Max Fedotov31-Aug-16 2:35 
GeneralRe: how to use Pin
Herilane31-Aug-16 3:22
professionalHerilane31-Aug-16 3:22 
GeneralRe: how to use Pin
Max Fedotov31-Aug-16 4:54
Max Fedotov31-Aug-16 4:54 
GeneralRe: how to use Pin
Herilane31-Aug-16 17:55
professionalHerilane31-Aug-16 17:55 
GeneralRe: how to use Pin
Max Fedotov31-Aug-16 21:16
Max Fedotov31-Aug-16 21:16 
GeneralRe: how to use Pin
Herilane31-Aug-16 21:50
professionalHerilane31-Aug-16 21:50 
Attempting to gather dependency information for package WPFTabTip.1.0.2 with respect to project touch3 , targeting .NETFramework,Version=v4.5.2
Attempting to resolve dependencies for package WPFTabTip.1.0.2 with DependencyBehavior Lowest
Resolving actions to install package WPFTabTip.1.0.2
Resolved actions to install package WPFTabTip.1.0.2
Removed package WPFTabTip.1.0.1 from packages.config
Successfully uninstalled WPFTabTip.1.0.1 from touch3
GET https://api.nuget.org/packages/wpftabtip.1.0.2.nupkg
OK https://api.nuget.org/packages/wpftabtip.1.0.2.nupkg 2351ms
Installing WPFTabTip 1.0.2.
Adding package WPFTabTip.1.0.2 to folder C:\Users\eps2\Documents\Visual Studio 2015\Projects\touch3\packages'
Added package WPFTabTip.1.0.2 to folder C:\Users\eps2\Documents\Visual Studio 2015\Projects\touch3\packages'
Added package WPFTabTip.1.0.2 to packages.config
Successfully installed WPFTabTip 1.0.2 to touch3
Removing package WPFTabTip.1.0.1 from folder C:\Users\eps2\Documents\Visual Studio 2015\Projects\touch3\packages
Removed package WPFTabTip.1.0.1 from folder C:\Users\eps2\Documents\Visual Studio 2015\Projects\touch3\packages
========== Finished ==========

That was painless, quick and too easy!
Clever. I see Nuget incorporates a webservice that goes to github and compares installed version with current version and does everything for you.

OK, you can now relax - the OSK is working fine in the project I've written, running under Win 10 and framework 4.5.2.

Now - your next mission, should you choose to accept it - is to create a drop-in replacement for the drab, colorless, unimaginative yet reliable Windows default OSK ! ;- }
GeneralRe: how to use Pin
Max Fedotov31-Aug-16 22:00
Max Fedotov31-Aug-16 22:00 
GeneralRe: how to use Pin
Herilane31-Aug-16 23:33
professionalHerilane31-Aug-16 23:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.