Detect if on-screen keyboard is open (TabTip.exe)

后端 未结 3 682
别跟我提以往
别跟我提以往 2020-12-09 12:30

I am working on a WPF/C# application for completing forms. I am trying to find a way to determine if the TapTip keyboard (TabTip.exe / metro-like keyboard for windows 8 desk

3条回答
  •  失恋的感觉
    2020-12-09 13:16

    This totally works!

    //
    // BOOL IsVirtualKeyboardVisible()
    //
    // Returns TRUE if Virtual Keyboard/Input Pane is visible
    // Returns FALSE if Virtual Keyboard/Input Pane is not visible
    
    __declspec(dllexport) BOOL __cdecl IsVirtualKeyboardVisible()
    {
        BOOL    bRet = FALSE;
        RECT    InputPaneScreenLocation = { 0, 0, 0, 0 };
    
        __try
        {
            HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    
            IFrameworkInputPane *IinputPane = NULL;
    
            if (SUCCEEDED(hr))
            {
                //
                // http://msdn.microsoft.com/en-us/library/windows/desktop/hh706967(v=vs.85).aspx
                //
                hr = CoCreateInstance(__uuidof(FrameworkInputPane), 0, CLSCTX_ALL, __uuidof(IFrameworkInputPane), (LPVOID*)&IinputPane);
                IinputPane->Location(&InputPaneScreenLocation);
    
                if (InputPaneScreenLocation.bottom == 0 && InputPaneScreenLocation.left == 0 &&
                    InputPaneScreenLocation.right == 0 && InputPaneScreenLocation.top == 0)
                {
                    // VKB is not visible
                    bRet = FALSE;
                }
                else
                {
                    // VKB is visible
                    bRet = TRUE;
                } 
            }
    
        }   // try
        __finally
        {
            CoUninitialize();
        }
    
        return bRet;
    }
    

提交回复
热议问题