| | |
macro building program help
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi again, i'm making a macro building pogram. I have got mouse movement down, but now i have no idea how to do mouse clicks or keyboard input. Please help! I'm also using dev-c++ 4.9.9.2.
Here's my complete code for the program.
Oh, and if you want to play a macro back, you have to do it right after you record it. I'm going to fix that.
Here's my complete code for the program.
c++ Syntax (Toggle Plain Text)
POINT MousePoint; int X = 0; int Y = 0; int MaxTime = 0; int Counter = 0; int NumOfResults = 0; int Xmax, Ymax = 0; int InputNumStr = 0; char Action = 'a'; int TempInt, InputInt = 0; char FileName[256] = "AAAAAAAAAAAAAAAAAAA"; char TempStr[256] = "AAAAAAAAAAAAAAAAAAA"; BOOL SetX = TRUE, SetY = FALSE; #include <windows.h> #include <iostream> #include <fstream> #include <cstring> #include "Macro.h" using namespace std; int main(int argc, char* argv[]) { cout << "MacroBuilder V. 1.0" << endl; cout << "\nEnter the name of the macro: "; cin >> FileName; strcat(FileName, ".txt"); std::ofstream SaveFile(FileName); SaveFile.close(); cout << "Type 'r' to record, 'q' to quit, 't' to test, or 'p' to play"; cin >> Action; while (Action != 'q') { switch(Action) { case 'r': MaxTime = 0; Counter = 0; NumOfResults = 0; cout << "Enter the max time of the macro in seconds: "; cin >> MaxTime; MaxTime = MaxTime * 10; cout << "\nPress escape to stop recording\n"; system("pause"); system("cls"); while (MaxTime > Counter) { GetCursorPos(&MousePoint); if (MousePoint.x < 10) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "000" << MousePoint.x; SaveFile.close(); cout << "\nX: 000" << MousePoint.x; } else if (MousePoint.x < 100) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "00" << MousePoint.x; SaveFile.close(); cout << "\nX: 00" << MousePoint.x; } else if (MousePoint.x < 1000) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "0" << MousePoint.x; SaveFile.close(); cout << "\nX: 0" << MousePoint.x; } else if (MousePoint.x > 1000) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "" << MousePoint.x; SaveFile.close(); cout << "\nX: " << MousePoint.x; } if (MousePoint.y < 10) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "000" << MousePoint.y; SaveFile.close(); cout << " Y: 000" << MousePoint.y; } else if (MousePoint.y < 100) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "00" << MousePoint.y; SaveFile.close(); cout << " Y: 00" << MousePoint.y; } else if (MousePoint.y < 1000) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "0" << MousePoint.y; SaveFile.close(); cout << " Y: 0" << MousePoint.y; } NumOfResults++; Sleep(10); Counter++; } cout << "\n\nDisplayed " << NumOfResults << " in " << (MaxTime / 10) << " seconds, " << "which is " << (NumOfResults) / (MaxTime / 10) << " results per second"; break; case 't': X = Y = 0; cout << "Enter the maximum X value: "; cin >> Xmax; cout << "\nEnter the maximum Y value: "; cin >> Ymax; system("pause"); system("cls"); // Move the mouse while (X < Xmax || Y < Ymax) { if (X < Xmax) { X++; } if (Y < Ymax) { Y++; } SetCursorPos(X,Y); // Get the mouse point GetCursorPos(&MousePoint); cout << MousePoint.x << ", "; cout << MousePoint.y << " "; Sleep(10); } break; case 'q': return 0; break; case 'p': SaveFile.close(); std::ifstream ReadFile(FileName); TempInt = InputInt = 0; X = Y = 0; char ch; /* cout << "\nRaw data:\n"; while (!ReadFile.eof()) { ReadFile.get(ch[2]); cout << ch[2]; } ReadFile.close(); ReadFile.open(FileName, ios::in);*/ while(!ReadFile.eof()) { Sleep(10); ReadFile.get(ch); TempInt++; switch (TempInt) { case 1: InputInt = atoi(&ch) * 1000; break; case 2: InputInt += atoi(&ch) * 100; break; case 3: InputInt += atoi(&ch) * 10; break; case 4: InputInt += atoi(&ch); TempInt = 0; if (SetX) { SetX = FALSE; SetY = TRUE; X = InputInt; cout << X << endl; } else if (SetY) { Y = InputInt; SetX = TRUE; SetY = FALSE; InputInt = 0; cout << Y << endl; SetCursorPos(X, Y); } } } ReadFile.close(); } // End switch /*for (TempInt = 0; TempInt < 256; TempInt++) { FileName[TempInt] = NULL; } */ cout << "\nType 'r' to record, 'q' to quit, 't' to test, or 'p' to play"; cin >> Action; } // End While return 0; }
Oh, and if you want to play a macro back, you have to do it right after you record it. I'm going to fix that.
Last edited by Ancient Dragon; Dec 28th, 2007 at 7:52 am. Reason: correct code tags
Its nice that you used code tags but you really should have formatted that code better before posting it. No one but a big masochist is going to read through all that stuff.
Last edited by Ancient Dragon; Dec 28th, 2007 at 8:04 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Voila:
Behold the power of copy, paste, a decent code editor, copy, paste, and post.
C++ Syntax (Toggle Plain Text)
POINT MousePoint; int X = 0; int Y = 0; int MaxTime = 0; int Counter = 0; int NumOfResults = 0; int Xmax, Ymax = 0; int InputNumStr = 0; char Action = 'a'; int TempInt, InputInt = 0; char FileName[256] = "AAAAAAAAAAAAAAAAAAA"; char TempStr[256] = "AAAAAAAAAAAAAAAAAAA"; BOOL SetX = TRUE, SetY = FALSE; #include <windows.h> #include <iostream> #include <fstream> #include <cstring> #include "Macro.h" using namespace std; int main(int argc, char* argv[]) { cout << "MacroBuilder V. 1.0" << endl; cout << "\nEnter the name of the macro: "; cin >> FileName; strcat(FileName, ".txt"); std::ofstream SaveFile(FileName); SaveFile.close(); cout << "Type 'r' to record, 'q' to quit, 't' to test, or 'p' to play"; cin >> Action; while ( Action != 'q' ) { switch ( Action ) { case 'r': MaxTime = 0; Counter = 0; NumOfResults = 0; cout << "Enter the max time of the macro in seconds: "; cin >> MaxTime; MaxTime = MaxTime * 10; cout << "\nPress escape to stop recording\n"; system("pause"); system("cls"); while ( MaxTime > Counter ) { GetCursorPos(&MousePoint); if ( MousePoint.x < 10 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "000" << MousePoint.x; SaveFile.close(); cout << "\nX: 000" << MousePoint.x; } else if ( MousePoint.x < 100 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "00" << MousePoint.x; SaveFile.close(); cout << "\nX: 00" << MousePoint.x; } else if ( MousePoint.x < 1000 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "0" << MousePoint.x; SaveFile.close(); cout << "\nX: 0" << MousePoint.x; } else if ( MousePoint.x > 1000 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "" << MousePoint.x; SaveFile.close(); cout << "\nX: " << MousePoint.x; } if ( MousePoint.y < 10 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "000" << MousePoint.y; SaveFile.close(); cout << " Y: 000" << MousePoint.y; } else if ( MousePoint.y < 100 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "00" << MousePoint.y; SaveFile.close(); cout << " Y: 00" << MousePoint.y; } else if ( MousePoint.y < 1000 ) { std::ofstream SaveFile(FileName, ios::app); SaveFile << "0" << MousePoint.y; SaveFile.close(); cout << " Y: 0" << MousePoint.y; } NumOfResults++; Sleep(10); Counter++; } cout << "\n\nDisplayed " << NumOfResults << " in " << (MaxTime / 10) << " seconds, " << "which is " << (NumOfResults) / (MaxTime / 10) << " results per second"; break; case 't': X = Y = 0; cout << "Enter the maximum X value: "; cin >> Xmax; cout << "\nEnter the maximum Y value: "; cin >> Ymax; system("pause"); system("cls"); // Move the mouse while ( X < Xmax || Y < Ymax ) { if ( X < Xmax ) { X++; } if ( Y < Ymax ) { Y++; } SetCursorPos(X,Y); // Get the mouse point GetCursorPos(&MousePoint); cout << MousePoint.x << ", "; cout << MousePoint.y << " "; Sleep(10); } break; case 'q': return 0; break; case 'p': SaveFile.close(); std::ifstream ReadFile(FileName); TempInt = InputInt = 0; X = Y = 0; char ch; /* cout << "\nRaw data:\n"; while (!ReadFile.eof()) { ReadFile.get(ch[2]); cout << ch[2]; } ReadFile.close(); ReadFile.open(FileName, ios::in);*/ while ( !ReadFile.eof() ) { Sleep(10); ReadFile.get(ch); TempInt++; switch ( TempInt ) { case 1: InputInt = atoi(&ch) * 1000; break; case 2: InputInt += atoi(&ch) * 100; break; case 3: InputInt += atoi(&ch) * 10; break; case 4: InputInt += atoi(&ch); TempInt = 0; if ( SetX ) { SetX = FALSE; SetY = TRUE; X = InputInt; cout << X << endl; } else if ( SetY ) { Y = InputInt; SetX = TRUE; SetY = FALSE; InputInt = 0; cout << Y << endl; SetCursorPos(X, Y); } } } ReadFile.close(); } // End switch /*for (TempInt = 0; TempInt < 256; TempInt++) { FileName[TempInt] = NULL; } */ cout << "\nType 'r' to record, 'q' to quit, 't' to test, or 'p' to play"; cin >> Action; } // End While return 0; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Linked List functions
- Next Thread: quick question about vectors
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






