locked
Virtual keyboard management with Win32 API RRS feed

  • Question

  • Hello,

    with my team we are developing a C++ Windows application which is based on Qt library for the UI part and on Win32 API for the rest.

    The minimum Windows version supported is Windows 8.1.

    We have some troubles to deal with the virtual keyboard. Indeed, due to some restrictions we can't use the Qt virtual keyboard and we have to handle the Windows virtual keyboard instead. The main issue is the possibility to detect if the keyboard is opened or not and to get its position, this to always display any text field of the application above the virtual keyboard.

    To do this we use the FindWindow function with different parameters, this to support several versions of Windows.

    "IPTIP_Main_Window" for version before 1803

    First child of ApplicationFrameWindow which is a Windows.UI.Core.CoreWindow window and has the caption "Microsoft Text Input Application" for version after 1803.

    In both cases the GetWindowLong function is used to get the GWL_STYLE value in order to know if the window is visible or not.

    The GetWindowRect function is used to get the position of the keyboard.

    The main problem is that depending on the Windows version of the user and on the update version this feature works or not.

    Each time a new Windows update version was released we had to adapt our code in order to support this new version.

    It will be very tedious and heavy for us to continue in this way.

    I'd like to know if there is any Win32 API component that we could use to get access to the virtual keyboard and to check its visibility and position.

    Regards,

    M Vidoine


    Wednesday, May 20, 2020 8:53 AM

All replies

    • Marked as answer by vidoine Thursday, May 28, 2020 8:34 AM
    • Unmarked as answer by vidoine Thursday, May 28, 2020 8:34 AM
    Wednesday, May 20, 2020 9:31 AM
  • IInputHostManagerBroker worked on my 2 last Windows 10 OS versions.

    Test =>

    typedef enum _DisplayMode
    {
    	NotSupported = 0,
    	Floating = 2,
    	Docked = 3,
    } DisplayMode;
    
    static const GUID CLSID_ImmersiveShellBroker = { 0x228826af, 0x02e1, 0x4226, 0xa9, 0xe0, 0x99, 0xa8, 0x55, 0xe4, 0x55, 0xa6 };
     
    MIDL_INTERFACE("2166ee67-71df-4476-8394-0ced2ed05274")
    IInputHostManagerBroker : public IUnknown
    {
    public:
    	virtual HRESULT STDMETHODCALLTYPE GetIhmLocation(RECT* rect, DisplayMode* mode) = 0;
    };
    
    MIDL_INTERFACE("9767060c-9476-42e2-8f7b-2f10fd13765c")
    IImmersiveShellBroker : public IUnknown
    {
    public:
    	virtual HRESULT STDMETHODCALLTYPE Dummy() = 0;
    	virtual HRESULT STDMETHODCALLTYPE GetInputHostManagerBroker(IInputHostManagerBroker** pInputHostManagerBroker) = 0;
    };

    IImmersiveShellBroker* pImmersiveShellBroker = NULL;
    HRESULT hr = CoCreateInstance(CLSID_ImmersiveShellBroker, NULL, CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pImmersiveShellBroker));
    if (SUCCEEDED(hr))
    {
    	IInputHostManagerBroker* pInputHostManagerBroker = NULL;
    	hr = pImmersiveShellBroker->GetInputHostManagerBroker(&pInputHostManagerBroker);
    	RECT rect = { 0 };
    	DisplayMode mode;
    	hr = pInputHostManagerBroker->GetIhmLocation(&rect, &mode);
    	// ...
    }



    Wednesday, May 20, 2020 9:39 AM
  • I'll try the two solutions and I'll tell you.
    Thanks for your help.
    Wednesday, May 20, 2020 12:31 PM
  • I tried the code, there was no issue at compilation or at runtime. The code seems to be good but that doesn't work properly.
    I put some logs in the hidding and showing functions but nothing is written.

    My problem is that due to lockdown with covid-19 I'm still in home office and I don't have any tablet to test. My colleagues have some but not me.
    I can only test on my office desktop which is a Windows 8.1, a Windows 10 virtual machine and my personal computer which is also
    on Windows 10.
    In desktop mode I launched manually the virtual keybaord from the task bar and I hid it but not log was displayed.
    In tablet mode the keyboard doesn't appear automatically when I set the focus on a text field even if I force it in the windows settings.

    • Marked as answer by vidoine Thursday, May 28, 2020 8:34 AM
    • Unmarked as answer by vidoine Thursday, May 28, 2020 8:34 AM
    Wednesday, May 27, 2020 2:22 PM
  • I tried the code, there was no issue at compilation or at runtime. The code seems to work properly.
    As I said I don't have a tablet at home so I can't really test. By launching manually the virtual keyboard the position seems to always be the same
    even if the keyboard is closed.
    ex: I launched the keyboard manually. (icon present in task bar)
         I closed it
         I launched my application
         The application saw it as visible

    Wednesday, May 27, 2020 2:25 PM
  • As I said I don't have a tablet at home so I can't really test.

    You could use the Tatlet mode in Windows 10.

    even if the keyboard is closed.
    ex: I launched the keyboard manually. (icon present in task bar)
         I closed it
         I launched my application
         The application saw it as visible

    IInputHostManagerBroker also works for me, the mode will be set as 0 if it is not visible.

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 28, 2020 7:52 AM
  • Ok, thanks.
    Even in Tablet mode the keyboard is not displayed automatically when I set the focus on a text field.

    Thursday, May 28, 2020 7:55 AM
  • If I draw a red rectangle (with FillRect) with rect returned by GetIhmLocation, it is drawn with correct coordinates/dimensions =>


    • Edited by Castorix31 Thursday, May 28, 2020 8:05 AM
    Thursday, May 28, 2020 8:05 AM
  • Yes, your code works properly. The code of @RLWA32 seems to not work in case of launching the keyboard manually.
    Thursday, May 28, 2020 10:05 AM