none
wpf 在pad上如何获取到虚拟键盘显示和消失的事件 RRS feed

  • 问题

  • 请教下,我有个程序在pad上运行,输入文字,将虚拟键盘弹出后,会被挡住,想通过方法调出虚拟键盘、虚拟键盘弹出事件、隐藏事件等,这些是否可行。

    谢谢

    2014年3月17日 6:50

答案

  • 你好,

    这里有一个解决方案,你可以检测进程中是否有虚拟键盘的进程(TabTip.exe)

    public MainWindow()
    {
                InitializeComponent();
                System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
                dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
                dispatcherTimer.Start();
    }
    
    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
                //Do something
                txb.Text = processIsRunning("TabTip") == false ? "No" : "Yes";
    
    }
    
    bool processIsRunning(string process)
    {
                //return (System.Diagnostics.Process.GetProcessesByName(process).Length != 0);
                System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName(process);
                
                return (processes.Length != 0);
    }

    截图:

    同样的,可以使用System.Diagnostics.Process去开启或者关闭虚拟键盘:

    if (processIsRunning("TabTip")==true)
    {
                    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("TabTip");
                    foreach (System.Diagnostics.Process proc in processes)
                    {
                        proc.Kill();
                    }
    }
    else
           myProcess = Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 skczjun 2014年3月19日 1:01
    2014年3月18日 7:05
    版主