How to know if the keyboard is active on a text input

前端 未结 4 1042
予麋鹿
予麋鹿 2021-01-23 07:57

I have an application that acts like an on screen keyboard, I need it to know if there is a keyboard cursor (caret) active any where, so the keyboard will set to active.

4条回答
  •  误落风尘
    2021-01-23 08:15

    It is easy by searching for the caret position, since it should be larger than 0

        GUITHREADINFO lpgui = new GUITHREADINFO();
        IntPtr fore = GetForegroundWindow();
        uint tpid = GetWindowThreadProcessId(fore, IntPtr.Zero);
        lpgui.cbSize = Marshal.SizeOf(lpgui.GetType());
        bool flag = GetGUIThreadInfo(tpid, out lpgui);
        WINDOWINFO pwi = new WINDOWINFO();
        pwi.cbSize = (uint)Marshal.SizeOf(pwi.GetType());
        GetWindowInfo((IntPtr)lpgui.hwndCaret, ref pwi);
    
        if (flag)
        {
            if (!(lpgui.rcCaret.Location.X == 0 && lpgui.rcCaret.Location.Y == 0))
            {
    
    
                //TODO
    
            }
        }
    

提交回复
热议问题