WPF TextBox 如何获取自定义虚拟软键盘输入的值

Mr_ALei 2017-01-10 09:44:46
如下图所示,目前是当窗体中的文本框获取焦点后将 自定义虚拟软键盘(keyboard.xaml) 通过keyboard.show() 显示出来,但是文本框获取不到通过虚拟软键盘输入的值,反而是电脑上任意一个软件中能输入文本值的地方,都可以通过这个弹出的软件盘进行字符输入,求教高手支招!谢谢
...全文
1878 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_37698796 2018-02-12
  • 打赏
  • 举报
回复
如果虚拟键盘和你的主窗口在同一个项目中,会出现点击键盘按钮后textbox的鼠标焦点转移的现象,解决方法是把虚拟键盘写成外部程序,通过打开外部程序的方法调用虚拟键盘。
不必了 2018-01-26
  • 打赏
  • 举报
回复
引用 5 楼 leivon 的回复:
楼主解决了么?
hello,请问你解决这个问题了吗?
不必了 2018-01-26
  • 打赏
  • 举报
回复
楼主解决了吗?我跟你用的一样的,我也是这个问题
xuggzu 2017-07-13
  • 打赏
  • 举报
回复
wpf子控件没有句柄,无法通过句柄相关方法发字符
leivon 2017-07-12
  • 打赏
  • 举报
回复
楼主解决了么?
Mr_ALei 2017-01-10
  • 打赏
  • 举报
回复
以下是部分虚拟软键盘源码

        [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);
Mr_ALei 2017-01-10
  • 打赏
  • 举报
回复
问题是别的软件凡是能输入值的地方,都可以用这个虚拟软键盘进行输入
exception92 2017-01-10
  • 打赏
  • 举报
回复
你自己定义的键盘窗口,不知道都留有什么接口,方法之类了。怎么支?
Mr_ALei 2017-01-10
  • 打赏
  • 举报
回复
有大神指教吗?

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧