9

我们正在开发一个在 Windows 7 平板电脑上运行的桌面 WPF应用程序,并且正在将一些带有 Windows 8 的 Surface Pro 单元添加到组合中。

我们立即注意到,当 TextBox 获得焦点时,小键盘图标不再显示。我们通过在所有文本框的 MouseDown 事件上运行“tabtip.exe”来解决它。

虽然我们有一些数字文本框(订单中商品的数量),并且想要打开屏幕键盘进行数字输入,但默认情况下它会使用 qwerty 键打开。

我一直在广泛搜索可以传递给 tabtip.exe 以更改其输入模式的任何命令行参数,但没有运气。对于 Metro 风格的应用来说,这似乎是一项微不足道的任务,但在桌面端却是不可能的。

我可以使用 tabtip.exe 的命令行参数来完成此操作吗?

4

4 回答 4

10

继@tymes 提供的答案之后,这是一个快速控制台应用程序,它演示了如何打开键盘并更改各种设置(C#)。:

using System;
using System.Diagnostics;
using Microsoft.Win32;

namespace CSharpTesting
{
    class Program
    {
        /// <summary>
        /// The different layout types on the virtual keyboard.
        /// </summary>
        public enum KeyboardLayoutMode
        {
            Default,
            ThumbLayout,
            Handwriting
        }

        /// <summary>
        /// The registry key which holds the keyboard settings.
        /// </summary>
        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);
        }

        /// <summary>
        /// Shows the onscreen keyboard.
        /// </summary>
        /// <param name="killExistingProcess">If true, kill any existing TabTip.exe process.</param>
        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);
        }

        /// <summary>
        /// Sets if the keyboard is in docked or floating mode.
        /// </summary>
        /// <param name="isDocked">If true set to docked, if false set to floating.</param>
        private static void SetKeyboardDockedMode(bool isDocked)
        {
            registryKey.SetValue("EdgeTargetDockedState", Convert.ToInt32(isDocked), RegistryValueKind.DWord);
        }

        /// <summary>
        /// Changes the layout mode of the keyboard.
        /// </summary>
        /// <param name="mode">The layout mode to use.</param>
        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;
            }
        }
    }
}
于 2014-07-16T09:32:58.027 回答
9

HKEY_CURRENT_USER\Software\Microsoft\TabletTip\1.7(Windows 8) 中更改 REG_DWORDKeyboardLayoutPreference 的值0是常规布局值1是中间​​带有数字键盘的拆分键盘

REG_DWORDLastUsedModalityWasHandwriting也必须是0或者如果1,当 tabtip 再次启动时,它将与笔手写区域一起打开。

于 2013-07-06T06:51:36.127 回答
1

您可以通过 Tabtip 的注册表设置来控制输入模式。查找名称为 KeyboardLayoutPreference 的注册表项。

于 2013-04-16T11:33:21.027 回答
1

我从未使用过 win 8,但在 win 10 中,您可以使用InputScope来控制使用的屏幕键盘:

<TextBox Grid.Row="0"
         InputScope="Number" />
<TextBox Grid.Row="1"
         InputScope="Default" />
于 2016-06-20T00:06:40.007 回答