多谢,但是不明白你的意思,另一个程序上的控件类型是未知的。只要是可以输入文字的控件,都肯那个是我判断的对象。正如前面提到的,其实我就是想判断当前是否处于可以输入文字的状态,如果是的话,就正常输入文字,
如果不是处于文字输入状态,则会启动自定义的键盘钩子,响应其他处理。

解决方案 »

  1.   

    能够想到这么复杂的逻辑,楼主不容易啊,看样子不是代码的问题啊,既然有的控件上有效,有的控件上无效,那应该是控件的问题,通过消息操作控件是很原始的控件了吧,这问题有点悬
      

  2.   

    控件都没有问题,因为都是别的程序上的控件,我感现在觉关键就是要想办法取到控件。
    可惜想不出啊想不出
      

  3.   

    得到了解决。
    分享一下方案。文字未被选择的情况下,winform程序和wpf程序都可以用GetGUIThreadInfo的hwndCaret来判断,是否是处于获得插入符的输入状态。
    在文字有被选择的情况下,对于winform程序依然可以用上述方法判断。
    对于wpf程序,要用到下面的类来判断。
    System.Windows.IInputElement inputElement = System.Windows.Input.Keyboard.FocusedElement;
    之后再将inputElement转换成TextBox和RichTextBox,然后判断他的IsReadOnly和IsEnabled的属性。
                    if (GetGUIThreadInfo(uiThreadid, ref stLpGui) == true)
                    {
                        if (stLpGui.hwndCaret != IntPtr.Zero)
                        {
                            //返回值 = 输入状态!
                        }
                        else
                        {
                            //返回值 = 非输入状态!
                            System.Windows.IInputElement inputElement = System.Windows.Input.Keyboard.FocusedElement;
                            if (inputElement != null)
                            {
                                if (inputElement is System.Windows.Controls.TextBox)
                                {
                                    if (((System.Windows.Controls.TextBox)inputElement).IsReadOnly == false && ((System.Windows.Controls.TextBox)inputElement).IsEnabled == true)
                                    {
                                        //返回值 = 输入状态!
                                    }
                                }
                                else if (inputElement is RichTextBox)
                                {
                                    if (((System.Windows.Controls.RichTextBox)inputElement).IsReadOnly == false && ((System.Windows.Controls.RichTextBox)inputElement).IsEnabled == true)
                                    {
                                        //返回值 = 输入状态!
                                    }
                                }
                            }
                        }
                    }