Windows 8 Desktop App: Open tabtip.exe to secondary keyboard (for numeric textbox)

前端 未结 4 1309
不知归路
不知归路 2020-12-05 12:11

We\'re working on a desktop WPF app that runs on Windows 7 tablets and are adding some Surface Pro units with windows 8 to the mix.

We noticed immed

4条回答
  •  执念已碎
    2020-12-05 12:52

    Following on from the answer @tymes provided, here is a quick console app which demonstrates opening the keyboard and changing various settings (C#).:

    using System;
    using System.Diagnostics;
    using Microsoft.Win32;
    
    namespace CSharpTesting
    {
        class Program
        {
            /// 
            /// The different layout types on the virtual keyboard.
            /// 
            public enum KeyboardLayoutMode
            {
                Default,
                ThumbLayout,
                Handwriting
            }
    
            /// 
            /// The registry key which holds the keyboard settings.
            /// 
            private static readonly RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\TabletTip\\1.7");
    
            static void Main(string[] args)
            {
                SetKeyboardDockedMode(true);
                SetKeyboardLayoutMode(KeyboardLayoutMode.ThumbLayout);
                ShowKeyboard(true);
            }
    
            /// 
            /// Shows the onscreen keyboard.
            /// 
            /// If true, kill any existing TabTip.exe process.
            public static void ShowKeyboard(bool killExistingProcess)
            {
                if (killExistingProcess)
                {
                    // If the user presses the close button on the keyboard then TabTip.exe will still run in the background. If we have made registry
                    // changes to the keyboard settings, they don't take effect until the process is started again so killing this ensures the keyboard
                    // will open with our new settings.
                    foreach (var process in Process.GetProcessesByName("TabTip"))
                    {
                        process.Kill();
                    }
                }
    
                string onScreenKeyboardPath = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
                Process.Start(onScreenKeyboardPath);
            }
    
            /// 
            /// Sets if the keyboard is in docked or floating mode.
            /// 
            /// If true set to docked, if false set to floating.
            private static void SetKeyboardDockedMode(bool isDocked)
            {
                registryKey.SetValue("EdgeTargetDockedState", Convert.ToInt32(isDocked), RegistryValueKind.DWord);
            }
    
            /// 
            /// Changes the layout mode of the keyboard.
            /// 
            /// The layout mode to use.
            private static void SetKeyboardLayoutMode(KeyboardLayoutMode mode)
            {
                switch (mode)
                {
                    case KeyboardLayoutMode.Handwriting:
                        registryKey.SetValue("KeyboardLayoutPreference", 0, RegistryValueKind.DWord);
                        registryKey.SetValue("LastUsedModalityWasHandwriting", 1, RegistryValueKind.DWord);
                        break;
                    case KeyboardLayoutMode.ThumbLayout:
                        registryKey.SetValue("KeyboardLayoutPreference", 1, RegistryValueKind.DWord);
                        registryKey.SetValue("LastUsedModalityWasHandwriting", 0, RegistryValueKind.DWord);
                        // 0 = small, 1 = medium, 2 = large
                        registryKey.SetValue("ThumbKeyboardSizePreference", 2, RegistryValueKind.DWord);
                        break;
                    default:
                        registryKey.SetValue("KeyboardLayoutPreference", 0, RegistryValueKind.DWord);
                        registryKey.SetValue("LastUsedModalityWasHandwriting", 0, RegistryValueKind.DWord);
                        break;
                }
            }
        }
    }
    

提交回复
热议问题