如下图所示,目前是当窗体中的文本框获取焦点后将 自定义虚拟软键盘(keyboard.xaml) 通过keyboard.show() 显示出来,但是文本框获取不到通过虚拟软键盘输入的值,反而是电脑上任意一个软件中能输入文本值的地方,都可以通过这个弹出的软件盘进行字符输入,求教高手支招!谢谢

解决方案 »

  1.   

    以下是部分虚拟软键盘源码        [DllImport("User32.dll")]
            public static extern int GetWindowLong(IntPtr hWnd, int nIdex);        [DllImport("User32.dll")]
            public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);        [DllImport("User32.dll")]
            public static extern void keybd_event(byte bVK, byte bScan, Int32 dwFlags, int dwExtraInfo);        [DllImport("User32.dll")]
            public static extern uint MapVirtualKey(uint uCode, uint uMapType);        [DllImport("user32.dll", EntryPoint = "GetKeyboardState")]
            public static extern int GetKeyboardState(byte[] pbKeyState);
            
            public static bool CapsLockStatus
            {
                get
                {
                    byte[] bs = new byte[256];
                    GetKeyboardState(bs);
                    return (bs[0x14] == 1);
                }
            }       public struct GUITHREADINFO
            {
                public int cbSize;
                public int flags;
                public int hwndActive;
                public int hwndFocus;
                public int hwndCapture;
                public int hwndMenuOwner;
                public int hwndMoveSize;
                public int hwndCaret;
                public System.Drawing.Rectangle rcCaret;
            }
            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool GetGUIThreadInfo(uint idThread, ref GUITHREADINFO lpgui);        [DllImport("user32")]
            public static extern IntPtr GetForegroundWindow();        [DllImport("user32", SetLastError = true)]
            public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
      

  2.   

    wpf子控件没有句柄,无法通过句柄相关方法发字符
      

  3.   

     
    hello,请问你解决这个问题了吗?
      

  4.   

    如果虚拟键盘和你的主窗口在同一个项目中,会出现点击键盘按钮后textbox的鼠标焦点转移的现象,解决方法是把虚拟键盘写成外部程序,通过打开外部程序的方法调用虚拟键盘。