6
votes

I am trying to bring up the Windows on-screen keyboard for an application developed with QT/C++. I currently have a custom on-screen keyboard, but it does not look very nice at all screen sizes, so I want to use the Windows native one. I want to bring the keyboard up automatically when the input focus is on a text box. I am new to QT, but not to C++. I have checked a few other similar questions, but it seems those solutions have not been much help.

Edit: The below solutions do not bring the keyboard up. They compile with no errors, but they do not actually bring up the osk.

void MainWindow::on_Button_released()
{
    ui->Button->setChecked(true);

    //Attempt 1
    //ShellExecute( NULL, NULL, L"osk.exe", NULL, NULL, SW_SHOW );

    //Attempt 2
    /* QObject *parent;
         QString program = "./osk.exe";
         QStringList arguments;
         //arguments << "-b" << "-t" << "input.txt";

         QProcess *myProcess = new QProcess(parent);
         myProcess->start(program);//, arguments);
    */

    //Attempt 3
    /* QProcess *process = new QProcess(this);
    QString file = QDir::homepath + "/tabtip.exe";
    process->start(file);
    */

    //Attempt 4
    /* 
    QProcess::execute ("start C:\\Windows\\System32\\osk.exe");
    */


    //Attempt 5
    system ("start C:\\Windows\\System32\\osk.exe");

}

**Attempt 5 specifically gives an error detailing that the file cannot be found, and it suggests checking that the correct path has been specified. I already verified the path, and osk.exe runs just fine -just not from within my application.

1
I'm really quite surprised that this question has been put on hold. Apart from needing some minor clarification it seems just fine to me.Paul Sanders
I am not so surprised...many people on here tend to try as hard as possible to get rid of questions rather than answer them. I only use this site as a last resort for that very reason.Kristina Gauthier
Edit your question (just a trivial edit will do). That will bring it to the attention of people who have the power to reopen it. My edit (being by a third party) does not have that effect. I upvoted, by the way. I'm sure you're not the only one who wants to do this.Paul Sanders
Fixed your problem launching osk - see below.Paul Sanders

1 Answers

5
votes

To display it, just launch osk.exe.

To get rid of it (*) (warning - undocumented behaviour):

HANDLE hWnd = FindWindowW (L"OSKMainClass", NULL);
if (hWnd)
{
     PostMessage (hWnd, WM_SYSCOMMAND, SC_CLOSE);
  // Or if you prefer:
  // PostMessage (hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}

I know this works on Windows 10, and probably back as far as Windows 7.

(*) I am indebted to @zett42 for this information (but I'm claiming the credit :)


Edit: It has come to my attention that launching OSK requires a little finesse. You can do it like this:

#include <shellapi.h>

void *was;
Wow64DisableWow64FsRedirection (&was);
ShellExecuteA (NULL, "open", "osk.exe", NULL, NULL, SW_SHOWNORMAL);
Wow64RevertWow64FsRedirection (was);

The Wow64... calls are only needed in a 32 bit app, and you need to link with shell32.lib.