pro里面加配置
LIBS += user32.lib
DEFINES+=_X86_
widget文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimer>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
int x,y;
QTimer* timer;
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
#include "windows.h"
#include "winuser.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
x=0;y=0;
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
ui->setupUi(this);
timer=new QTimer();
timer->setInterval(500);
connect(ui->pushButton, &QPushButton::clicked,[this](){
//mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,70,10,0,0);
timer->start();
});
connect(timer, &QTimer::timeout,[this](){
/*x+=10;y+=10;
ui->pushButton->setText(QString("%1:%2").arg(x).arg(y));
mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,x,y,0,0);
if(x>=1920||y>=1080)
{
x=0;y=0;
}*/
keybd_event('a', 0, 0, 0);
keybd_event('a', 0, KEYEVENTF_KEYUP, 0);
});
/*
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event('a', 0, 0, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
keybd_event('a', 0, KEYEVENTF_KEYUP, 0);
*/
}
Widget::~Widget()
{
delete ui;
}