Click the button in other application using QT
-
wrote on 23 Jul 2020, 05:34 last edited by TomNow99
Hello,
I would like to write application in QT which can programatically click on button in other application ( this other app can be written in other language like java or c# ). I know that is application spy++, which give me information about this button. But how can I send signal that I want click on it?
If this is impossible in QT maybe someone know how can I write this using winapi? I try with
HWND hwndApp =FindWindow(NULL, L"otherAppTitle"); HWND ButtonHandle = FindWindowEx(hwndApp , NULL, NULL, L"pushButton");
but I don't get proper ButtonHandle ( ButtonHandle is 0x0 ). Next I know that I can using SendMessage() function, but my goal is to get proper ButtonHandle.
"pushButton" is the name of the QPushButton and his text.
I try with:
HWND top_child = GetWindow(FindWindow(NULL, L"otherAppTitle"), GW_CHILD);
too. But still 0x0
-
Hello,
I would like to write application in QT which can programatically click on button in other application ( this other app can be written in other language like java or c# ). I know that is application spy++, which give me information about this button. But how can I send signal that I want click on it?
If this is impossible in QT maybe someone know how can I write this using winapi? I try with
HWND hwndApp =FindWindow(NULL, L"otherAppTitle"); HWND ButtonHandle = FindWindowEx(hwndApp , NULL, NULL, L"pushButton");
but I don't get proper ButtonHandle ( ButtonHandle is 0x0 ). Next I know that I can using SendMessage() function, but my goal is to get proper ButtonHandle.
"pushButton" is the name of the QPushButton and his text.
I try with:
HWND top_child = GetWindow(FindWindow(NULL, L"otherAppTitle"), GW_CHILD);
too. But still 0x0
-
Hi
I would try with https://www.autoitscript.com/site/
and if it cant push the button. Nothing can. -
wrote on 23 Jul 2020, 08:24 last edited by
I try with:
#include "mainwindow.h" #include "ui_mainwindow.h" #include "windows.h" #include <QDebug> BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam) { qDebug() << "tmp message"; return TRUE; } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); HWND hWndParent = FindWindow( NULL, L"abcde" ); qDebug() << "address" << hWndParent; EnumChildWindows( hWndParent, EnumChildProc, NULL ); } MainWindow::~MainWindow() { delete ui; }
but with no positive result ( I don't see any child of "abcde" ).
qDebug from hWndParent is good - I get it, but no his childs ( I don't see any "tmp message" ).
-
I try with:
#include "mainwindow.h" #include "ui_mainwindow.h" #include "windows.h" #include <QDebug> BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam) { qDebug() << "tmp message"; return TRUE; } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); HWND hWndParent = FindWindow( NULL, L"abcde" ); qDebug() << "address" << hWndParent; EnumChildWindows( hWndParent, EnumChildProc, NULL ); } MainWindow::~MainWindow() { delete ui; }
but with no positive result ( I don't see any child of "abcde" ).
qDebug from hWndParent is good - I get it, but no his childs ( I don't see any "tmp message" ).
@TomNow99
Hi
is that a QPushbutton ?You have to understand if the control/button is not a native windows control, it wont have a handle and
wont show up with EnumChildWindowsSo its not really easy to automate a Qt app from outside for instance.
-
@TomNow99
Hi
I not seen anything that works purely from outside that can automate Qt app.Can you tell what goal is ?
Maybe there is other way to archive that. -
wrote on 23 Jul 2020, 08:47 last edited by TomNow99
Sometimes I would like to automate some GUI application which often don't have native windows controls. I know that some app I can control from QT ( for example excel ), but I think ( for example ) about apps to sell in a shop too, which are custom by owners of the shop.
-
Sometimes I would like to automate some GUI application which often don't have native windows controls. I know that some app I can control from QT ( for example excel ), but I think ( for example ) about apps to sell in a shop too, which are custom by owners of the shop.
@TomNow99
Well for custom widgets, you cannot use win API for it.
Then you would have to hand code something that moves mouse to button and clicks.Browsers have anti measure for this so that dont often work.
But for other apps it will.- which are custom by owners of the shop.
So thats inside a browser ?
- which are custom by owners of the shop.
-
wrote on 23 Jul 2020, 08:56 last edited by
@mrjj Now I think about Desktop apps.
I thought about move mouse to button and click too. But how can I do this? Do you think about: open that dekstop app, check (x,y) mouse's position and write app to simulate clicking in this place? This is solution, but I think it is very bad. Do you know better?
-
@mrjj Now I think about Desktop apps.
I thought about move mouse to button and click too. But how can I do this? Do you think about: open that dekstop app, check (x,y) mouse's position and write app to simulate clicking in this place? This is solution, but I think it is very bad. Do you know better?
@TomNow99
Hi
In Qt you can use QCursor to move mouse around.I used autoit and https://www.autoitscript.com/forum/files/file/471-image-search-udf/
to search for the button with image so if window was moved then it would still find it.
Its not a nice solution but i never found anything better. -
wrote on 23 Jul 2020, 09:30 last edited by
@mrjj Thank you. I checked QCursor and it's work perfect. Can you tell me how Can I click using Qt?
I would like to move mouse cursor using QCursor and when cursor is above some icon with exe I would like to double click on this icon and run an exe.
-
@mrjj Thank you. I checked QCursor and it's work perfect. Can you tell me how Can I click using Qt?
I would like to move mouse cursor using QCursor and when cursor is above some icon with exe I would like to double click on this icon and run an exe.
@TomNow99
Hi
I have not tried with Qt.
but maybe#include <QTest>
QTest::mouseClick(d, Qt::LeftButton, Qt::NoModifier, QPoint(x,y));
i dont know if this works externally !else its via windows api and send message
1/13