How to force an event in external application? (controlling)

  • Hi, i'm curious about the ability to control external software, i've already used QProcess with console applications, providing std input to the "controlled" process, but how do i deal with any other kind of programs? for example, is there a way to send "escape key pressed" event to some pre-menu annoying video in a PC game to skip it? if it is not possible in Qt libs, are there any other tools to achieve that with the lovely Qt framework? thanks in advance!

  • Qt Champions 2017

    If on windows platform.
    I would use Autoit3
    It has all you need for such things.

    Often such controlling will require a platform specific solution.
    for windows, it would be something like:

    HWND notepad = FindWindow(_T("Notepad"), NULL);
    HWND edit = FindWindowEx(notepad, NULL, _T("Edit"), NULL);
    SendMessage(edit, WM_SETTEXT, NULL, (LPARAM)_T("hello"));

  • @mrjj thanks, but i need a C++ solution for it..
    there must be something

  • Qt Champions 2017

    Ok no autoit3 then :)

    well read

    If you mean , you want a pure qt platform neutral solution, I have no idea. sorry.

  • Moderators

    Unless the app has some mechanism built in to be interacted with (like standard in/out, app switches or some interface like dbus or rpc) there is no cross-platform way to do it.
    Even on a specific platform there might not be, depending on multitude of factors.

    On Windows you might try to sniff controls handles with something like spy++ (bundled with Visual Studio) and send OS messages (WM_XXX) to them, but that's hacky at best and will not work for example with Qt apps which mostly bypass native rendering and windowing.With Qt apps you might try to tinker with the app like Froglogic Squish tools do to get to know QObject structure of the app, but that's again very limited as you need to know the exact version of Qt used.

    In general this is a very bad bad idea. If an app doesn't provide you with a documented API to do it then it most likely doesn't want/can't handle such tinkering and you should not do it. It's basically reverse engineering and relying on undocumented behavior and anything you come up with will most likely break the minute the next version of the app comes out.

    Oh, and I'm not mentioning the legal aspect of such stuff, as you're probably aware that a lot of licences forbid this kind of outside modifications of running apps.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.