⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

How to send key press to other application?

  • I'm trying to make autotyper in qt. I need to simulate key press to other application(eg-firefox) according to text. Is there a way I can do this through QApplication::sendEvent() since it needs ref to receiver or any other way?

    Thanks for help.

  • @krillxox
    QApplication::sendEvent() is for sending within the application, not externally.
    Firefox is not a Qt application, so you can't use Qt Remote Objects, as I understand it.
    So far as I know, the only way to "send key press to other application" is under Windows where there is a Win (not Qt) call for sending keys to other processes.

  • Is there a way I can do this in linux and mac?

  • Lookup pywinauto. This is a windows python automation library. You can dig into the code to see what it has to do to send events to apps. Then look for something similar in linux and mac. Each platform will be different and require a different api. For instance on Linux you will have to support X11 and Wayland potentially. So that could double the work. Python is often used to automate things so you have a better bet of finding something that already works and and can show you how the api on that platform works.

Log in to reply