Open and close the system on-screen keyboard in Qt

There are many examples on the Internet, all of which realize the opening of the system on-screen keyboard, but the closing cannot be realized.

Pro-test the effective method in qt, using the win10 system.

import header file

#include <Windows.h>

#pragma comment(lib, "user32.lib")//Open the on-screen keyboard to use the header file

There are two on-screen keyboards, one osk.exe and one TabTip.exe

How to open the osk keyboard:

PVOID OldValue;

BOOL bRet = Wow64DisableWow64FsRedirection (&OldValue);

QString keyboardpath="C:\\Windows\\System32\\osk.exe";

QString params="";

ShellExecute(NULL, L"open", (LPCWSTR)keyboardpath.utf16(), (LPCWSTR)params.utf16(), NULL, SW_SHOWNORMAL);

if (bRet)

{

  Wow64RevertWow64FsRedirection(OldValue);

}

closure:

HWND appWnd;

appWnd = ::FindWindow(L"OSKMainClass", NULL);

if (appWnd)

{

   SendMessage(appWnd, WM_SYSCOMMAND, SC_CLOSE, 0);

    qDebug() << "closeKeyboard succeed";

}

else

{

    qDebug() << "closeKeyboard failed";

 }

TabTip.exe keyboard is called in the same way as osk.exe, but the path is different

QString keyboardpath="C:\\Program Files\\Common Files\\microsoft shared\\ink\\TabTip.exe";

closure:

appWnd = ::FindWindow(L"IPTIP_Main_Window", NULL);

Others are the same as osk shutdown

 

 

Notice:

SendMessage(appWnd, WM_SYSCOMMAND, SC_CLOSE, 0);

The parameters in this function should be written like this, both closing the keyboard are valid,

Written as SendMessage(appWnd, WM_CLOSE,0, 0); it has no effect, I tested it myself.

Guess you like

Origin blog.csdn.net/liujing_sy/article/details/100535286