首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在打开数字板视图的情况下启动TabTip

在打开数字板视图的情况下启动TabTip
EN

Stack Overflow用户
提问于 2014-01-15 23:02:37
回答 1查看 11.2K关注 0票数 5

我基本上有启动键盘的代码,但它是在字母数字部分打开的,用于编辑的框是一个带有数字的NumericUpDown。所以,我想在windows8.1中打开tabtip.exe,也就是屏幕上的键盘,把数字键盘作为焦点。这是我当前打开tabtip的代码,但默认情况下它不是用numpad打开的:

代码语言:javascript
运行
复制
using System.Runtime.InteropServices; //added for keyboard closure
using System.Windows.Interop; //Keyboard closure - must add reference for WindowsBase

//Added for keyboard closure
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);

        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(String sClassName, String sAppName);

//open keyboard
void openKeyboard()
{
                ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                Process.Start(startInfo);
}

//close keyboard
void closeKeyboard()
{
uint WM_SYSCOMMAND = 274;
                uint SC_CLOSE = 61536;
                IntPtr KeyboardWnd = FindWindow("IPTip_Main_Window", null);
                PostMessage(KeyboardWnd.ToInt32(), WM_SYSCOMMAND, (int)SC_CLOSE, 0);
}

似乎还有一些注册表编辑你可以做的,但我似乎不能让它使数字键盘的键盘在windows8.1中显示:

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

EN

回答 1

Stack Overflow用户

发布于 2014-05-02 22:23:12

目前在Windows 8.1中,似乎没有多少功能是以编程方式公开的。下面的代码将导致tabtip.exe读取注册表,因为原始进程已终止。它不是完全可靠的,但它是响应某些注册表值的一种方式。关于停靠的部分是可选的,它通过注册表的更改强制它每次停靠。process.Kill();应该在try/catch中,因为它偶尔没有权限,可能会抛出异常。

代码语言:javascript
运行
复制
    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string sClassName, string sAppName);

    [DllImport("user32.dll")]
    public static extern IntPtr PostMessage(int hWnd, uint msg, int wParam, int lParam);

    private static void KillTabTip()
    {
        // Kill the previous process so the registry change will take effect.
        var processlist = Process.GetProcesses();

        foreach (var process in processlist.Where(process => process.ProcessName == "TabTip"))
        {
            process.Kill();
            break;
        }
    }

    public void ShowTouchKeyboard(bool isVisible, bool numericKeyboard)
    {
        if (isVisible)
        {
            const string keyName = "HKEY_CURRENT_USER\\Software\\Microsoft\\TabletTip\\1.7";

            var regValue = (int) Registry.GetValue(keyName, "KeyboardLayoutPreference", 0);
            var regShowNumericKeyboard = regValue == 1;

            // Note: Remove this if do not want to control docked state.
            var dockedRegValue = (int) Registry.GetValue(keyName, "EdgeTargetDockedState", 1);
            var restoreDockedState = dockedRegValue == 0;

            if (numericKeyboard && regShowNumericKeyboard == false)
            {
                // Set the registry so it will show the number pad via the thumb keyboard.
                Registry.SetValue(keyName, "KeyboardLayoutPreference", 1, RegistryValueKind.DWord);

                // Kill the previous process so the registry change will take effect.
                KillTabTip();
            }
            else if (numericKeyboard == false && regShowNumericKeyboard)
            {
                // Set the registry so it will NOT show the number pad via the thumb keyboard.
                Registry.SetValue(keyName, "KeyboardLayoutPreference", 0, RegistryValueKind.DWord);

                // Kill the previous process so the registry change will take effect.
                KillTabTip();
            }

            // Note: Remove this if do not want to control docked state.
            if (restoreDockedState)
            {
                // Set the registry so it will show as docked at the bottom rather than floating.
                Registry.SetValue(keyName, "EdgeTargetDockedState", 1, RegistryValueKind.DWord);

                // Kill the previous process so the registry change will take effect.
                KillTabTip();
            }

            Process.Start("c:\\Program Files\\Common Files\\Microsoft Shared\\ink\\TabTip.exe");
        }
        else
        {
            var win8Version = new Version(6, 2, 9200, 0);

            if (Environment.OSVersion.Version >= win8Version)
            {
                const uint wmSyscommand = 274;
                const uint scClose = 61536;
                var keyboardWnd = FindWindow("IPTip_Main_Window", null);
                PostMessage(keyboardWnd.ToInt32(), wmSyscommand, (int)scClose, 0);
            }
        }
    }

您可以从自定义版本的TextBox中调用上述方法,其中OnTouchDown将被覆盖,并创建一个额外的DependencyProperty以指示字段是否使用NumericKeyboard:

代码语言:javascript
运行
复制
    #region NumericKeyboard
    public static readonly DependencyProperty NumericKeyboardProperty = DependencyProperty.Register("NumericKeyboard", typeof(bool), typeof(CustomTextBox), new FrameworkPropertyMetadata(false));

    /// <summary> Returns/set the "NumericKeyboard" state of the CustomTextBox. </summary>
    public bool NumericKeyboard
    {
        get { return (bool)GetValue(NumericKeyboardProperty); }
        set { SetValue(NumericKeyboardProperty, value); }
    }
    #endregion


    protected override void OnTouchDown(TouchEventArgs e)
    {
        base.OnTouchDown(e);
        Focus();

        if (IsReadOnly == false)
            ShowTouchKeyboard(true, NumericKeyboard);
    }

目前,我还没有成功地使用类似的技术在浮动(非停靠)状态下在屏幕周围定位TabTip窗口。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21140852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档