//------------------------------> Start of autofish.h <------------------------------------ #ifndef AUTOFISH_H #define AUTOFISH_H #pragma once #include #include #include #include #include namespace Ui { class AutoFish; } class AutoFish : public QMainWindow { Q_OBJECT public: explicit AutoFish(QWidget *parent = 0); ~AutoFish(); void updatelabel(QString str); private slots: void on_quitButton_clicked(); void on_startButton_clicked(); void on_statusLabel_objectNameChanged(const QString &objectName); private: Ui::AutoFish *ui; }; #endif // AUTOFISH_H //------------------------------> Start of main.cpp <------------------------------------ #include "autofish.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); AutoFish w; w.show(); return a.exec(); } //------------------------------> Start of autofish.cpp <------------------------------------ #include "autofish.h" #include "ui_autofish.h" AutoFish::AutoFish(QWidget *parent) : QMainWindow(parent), ui(new Ui::AutoFish) { ui->setupUi(this); } AutoFish::~AutoFish() { delete ui; } void AutoFish::on_quitButton_clicked() { qApp->quit(); } //Function to set the text in the status bar. void AutoFish::updatelabel(QString str) { ui->statusLabel->setText(str); std::cout << "End of function!" << std::endl; } //Function to enable the ability to modify memory of a process. //void EnableDebugPriv(); HWND getWindow(LPCSTR processName); void AutoFish::on_startButton_clicked() { //The handle for the window. HWND window = getWindow("FFXIVLauncher"); // Bring specified window into focus SetForegroundWindow(window); // This structure will be used to create the keyboard input event INPUT ip; // Pause for 1 second. Sleep(3000); // Set up a generic keyboard event. ip.type = INPUT_KEYBOARD; ip.ki.wScan = 0; // hardware scan code for key ip.ki.time = 0; ip.ki.dwExtraInfo = 0; //List of virtual key codes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx // Press the "A" key ip.ki.wVk = 0x41; // virtual-key code for the "a" key ip.ki.dwFlags = 0; // 0 for key press SendInput(1, &ip, sizeof(INPUT)); // Release the "A" key ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release SendInput(1, &ip, sizeof(INPUT)); } //Returns the window handle of the given process. HWND getWindow(LPCSTR processName) { HWND hwnd = FindWindowA(0, processName); if(!hwnd) { std::cout << "Error: Cannot find window!" << std::endl; updatelabel("Error: Cannot find window."); } else { std::cout << "Seccess! Window found!" << std::endl; updatelabel("Seccess! Window Found!"); } return hwnd; }