在QT应用中使用Windows 10屏幕键盘

编程入门 行业动态 更新时间:2024-10-24 16:27:44
本文介绍了在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屏幕键盘

本文发布于:2023-10-25 22:18:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:屏幕   键盘   QT   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!