在QT应用中使用Windows 10屏幕键盘 [英] Using Windows 10 on-screen keyboard in QT app

查看:786
本文介绍了在QT应用中使用Windows 10屏幕键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为使用QT/C ++开发的应用程序打开Windows屏幕键盘.我目前有一个自定义的屏幕键盘,但在所有屏幕尺寸上看起来都不太好,所以我想使用Windows原生键盘.当输入焦点位于文本框上时,我想自动调高键盘.我是QT的新手,但不熟悉C ++.我已经检查了其他一些类似的问题,但似乎这些解决方案并没有太大帮助.

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.

以下解决方案无法启动键盘.它们编译时没有错误,但实际上并没有启动osk.

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");

}

**尝试5专门给出一个错误,详细说明找不到文件,它建议检查是否已指定正确的路径.我已经验证了路径,并且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.

推荐答案

要显示它,只需启动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);
}

我知道这可以在Windows 10上运行,甚至可以追溯到Windows 7.

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

(*)我很想知道@ zett42的信息(但我要声明所有权:)

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

我已经注意到启动OSK需要一些技巧.您可以这样做:

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);

仅在32位应用程序中需要Wow64...调用,并且您需要与shell32.lib链接.

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

这篇关于在QT应用中使用Windows 10屏幕键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆