Search code examples
winapiqteventskeyevent

Simulate QKeyEvent on Whatever Widget InFocus


I want to Simulate a QKeyEvent on the Currently Focused Widget. That widget Might not belong to My Application even the widget may not be an Qt Widget at all. I just want to Simulate a QKeyEvent On Whatever Widget In Focus now.

I've tried QApplication::postEvent(DG::Util::_desktopWidget, ev); Where DG::Util::_desktopWidget is the Primary Desktop Widget

QDesktopWidget* desktopWidget = new QDesktopWidget;
DG::Util::_desktopWidget = desktopWidget->screen(desktopWidget->primaryScreen());

But This doesn't work.


Solution

  • With Qt you can only control widgets belonging to your app. Therefore you can't send QKeyEvent to non-Qt apps, or Qt apps which are different processes.