Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

AutoFish

By: a guest on Sep 6th, 2013  |  syntax: C++  |  size: 2.97 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. //------------------------------> Start of autofish.h <------------------------------------
  3. #ifndef AUTOFISH_H
  4. #define AUTOFISH_H
  5.  
  6. #pragma once
  7.  
  8. #include <QMainWindow>
  9.  
  10. #include <stdio.h>
  11. #include <tchar.h>
  12.  
  13. #include <windows.h>
  14. #include <iostream>
  15.  
  16. namespace Ui {
  17. class AutoFish;
  18. }
  19.  
  20. class AutoFish : public QMainWindow
  21. {
  22.     Q_OBJECT
  23.  
  24. public:
  25.     explicit AutoFish(QWidget *parent = 0);
  26.     ~AutoFish();
  27.     void updatelabel(QString str);
  28.  
  29. private slots:
  30.     void on_quitButton_clicked();
  31.  
  32.     void on_startButton_clicked();
  33.  
  34.     void on_statusLabel_objectNameChanged(const QString &objectName);
  35.  
  36. private:
  37.     Ui::AutoFish *ui;
  38. };
  39.  
  40. #endif // AUTOFISH_H
  41.  
  42.  
  43. //------------------------------> Start of main.cpp <------------------------------------
  44. #include "autofish.h"
  45. #include <QApplication>
  46.  
  47. int main(int argc, char *argv[])
  48. {
  49.     QApplication a(argc, argv);
  50.     AutoFish w;
  51.     w.show();
  52.  
  53.     return a.exec();
  54. }
  55.  
  56.  
  57. //------------------------------> Start of autofish.cpp <------------------------------------
  58. #include "autofish.h"
  59. #include "ui_autofish.h"
  60.  
  61. AutoFish::AutoFish(QWidget *parent) :
  62.     QMainWindow(parent),
  63.     ui(new Ui::AutoFish)
  64. {
  65.     ui->setupUi(this);
  66. }
  67.  
  68. AutoFish::~AutoFish()
  69. {
  70.     delete ui;
  71. }
  72.  
  73. void AutoFish::on_quitButton_clicked()
  74. {
  75.     qApp->quit();
  76. }
  77.  
  78. //Function to set the text in the status bar.
  79. void AutoFish::updatelabel(QString str)
  80. {
  81.     ui->statusLabel->setText(str);
  82.  
  83.     std::cout << "End of function!" << std::endl;
  84. }
  85.  
  86.  
  87. //Function to enable the ability to modify memory of a process.
  88. //void EnableDebugPriv();
  89. HWND getWindow(LPCSTR processName);
  90.  
  91. void AutoFish::on_startButton_clicked()
  92. {
  93.     //The handle for the window.
  94.     HWND window = getWindow("FFXIVLauncher");
  95.  
  96.     // Bring specified window into focus
  97.     SetForegroundWindow(window);
  98.  
  99.     // This structure will be used to create the keyboard input event
  100.     INPUT ip;
  101.  
  102.     // Pause for 1 second.
  103.     Sleep(3000);
  104.  
  105.     // Set up a generic keyboard event.
  106.     ip.type = INPUT_KEYBOARD;
  107.     ip.ki.wScan = 0; // hardware scan code for key
  108.     ip.ki.time = 0;
  109.     ip.ki.dwExtraInfo = 0;
  110.  
  111.     //List of virtual key codes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx
  112.     // Press the "A" key
  113.     ip.ki.wVk = 0x41; // virtual-key code for the "a" key
  114.     ip.ki.dwFlags = 0; // 0 for key press
  115.     SendInput(1, &ip, sizeof(INPUT));
  116.  
  117.     // Release the "A" key
  118.     ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
  119.     SendInput(1, &ip, sizeof(INPUT));
  120. }
  121.  
  122. //Returns the window handle of the given process.
  123. HWND getWindow(LPCSTR processName) {
  124.     HWND hwnd = FindWindowA(0, processName);
  125.     if(!hwnd) {
  126.         std::cout << "Error: Cannot find window!" << std::endl;
  127.         updatelabel("Error: Cannot find window.");
  128.     }
  129.     else {
  130.         std::cout << "Seccess! Window found!" << std::endl;
  131.         updatelabel("Seccess! Window Found!");
  132.     }
  133.     return hwnd;
  134. }
clone this paste RAW Paste Data