I am trying to make an application where the mouse goes to certain locations on screen and automatically clicks left button. The problem is I cant click outside the Qt application so I made a workaround by making the application transparent to mouse clicks and making it full screen using this code:
int x = 800;
int y = 500;
this->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint|Qt::ToolTip);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setAttribute( Qt::WA_TransparentForMouseEvents);
QCursor::setPos(x,y);
qDebug()<<QCursor::pos();
QWidget *d = QApplication::desktop()->screen();
QMouseEvent MouseEvent(QEvent::MouseButtonPress, QCursor::pos(),Qt::LeftButton,Qt::LeftButton, Qt::NoModifier);
QApplication::sendEvent(d, &MouseEvent);
QApplication::sendEvent(d, &MouseEvent);
The mouse cursor moves to the desired location but the clicking doesn't work. I also tried replacing the Qt class for handling mouse events and use windows API since I don't really need cross-platform application but I am getting stuck at the same point.