macro building program help

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

macro building program help

 
0
  #1
Dec 27th, 2007
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.

  1.  
  2. POINT MousePoint;
  3. int X = 0;
  4. int Y = 0;
  5. int MaxTime = 0;
  6. int Counter = 0;
  7. int NumOfResults = 0;
  8. int Xmax, Ymax = 0;
  9. int InputNumStr = 0;
  10. char Action = 'a';
  11. int TempInt, InputInt = 0;
  12. char FileName[256] = "AAAAAAAAAAAAAAAAAAA";
  13. char TempStr[256] = "AAAAAAAAAAAAAAAAAAA";
  14. BOOL SetX = TRUE, SetY = FALSE;
  15.  
  16. #include <windows.h>
  17. #include <iostream>
  18. #include <fstream>
  19. #include <cstring>
  20. #include "Macro.h"
  21.  
  22. using namespace std;
  23. int main(int argc, char* argv[])
  24. {
  25. cout << "MacroBuilder V. 1.0" << endl;
  26. cout << "\nEnter the name of the macro: ";
  27. cin >> FileName;
  28. strcat(FileName, ".txt");
  29.  
  30. std::ofstream SaveFile(FileName);
  31. SaveFile.close();
  32. cout << "Type 'r' to record, 'q' to quit, 't' to test, or 'p' to play";
  33. cin >> Action;
  34.  
  35. while (Action != 'q')
  36. {
  37.  
  38. switch(Action)
  39. {
  40. case 'r':
  41. MaxTime = 0;
  42. Counter = 0;
  43. NumOfResults = 0;
  44. cout << "Enter the max time of the macro in seconds: ";
  45. cin >> MaxTime;
  46. MaxTime = MaxTime * 10;
  47. cout << "\nPress escape to stop recording\n";
  48. system("pause");
  49. system("cls");
  50. while (MaxTime > Counter)
  51. {
  52. GetCursorPos(&MousePoint);
  53. if (MousePoint.x < 10)
  54. {
  55. std::ofstream SaveFile(FileName, ios::app);
  56. SaveFile << "000" << MousePoint.x;
  57. SaveFile.close();
  58. cout << "\nX: 000" << MousePoint.x;
  59. }
  60. else if (MousePoint.x < 100)
  61. {
  62. std::ofstream SaveFile(FileName, ios::app);
  63. SaveFile << "00" << MousePoint.x;
  64. SaveFile.close();
  65. cout << "\nX: 00" << MousePoint.x;
  66. }
  67. else if (MousePoint.x < 1000)
  68. {
  69. std::ofstream SaveFile(FileName, ios::app);
  70. SaveFile << "0" << MousePoint.x;
  71. SaveFile.close();
  72. cout << "\nX: 0" << MousePoint.x;
  73. }
  74. else if (MousePoint.x > 1000)
  75. {
  76. std::ofstream SaveFile(FileName, ios::app);
  77. SaveFile << "" << MousePoint.x;
  78. SaveFile.close();
  79. cout << "\nX: " << MousePoint.x;
  80. }
  81.  
  82. if (MousePoint.y < 10)
  83. {
  84. std::ofstream SaveFile(FileName, ios::app);
  85. SaveFile << "000" << MousePoint.y;
  86. SaveFile.close();
  87. cout << " Y: 000" << MousePoint.y;
  88. }
  89. else if (MousePoint.y < 100)
  90. {
  91. std::ofstream SaveFile(FileName, ios::app);
  92. SaveFile << "00" << MousePoint.y;
  93. SaveFile.close();
  94. cout << " Y: 00" << MousePoint.y;
  95. }
  96. else if (MousePoint.y < 1000)
  97. {
  98. std::ofstream SaveFile(FileName, ios::app);
  99. SaveFile << "0" << MousePoint.y;
  100. SaveFile.close();
  101. cout << " Y: 0" << MousePoint.y;
  102. }
  103.  
  104. NumOfResults++;
  105. Sleep(10);
  106. Counter++;
  107. }
  108. cout << "\n\nDisplayed " << NumOfResults << " in " << (MaxTime / 10) << " seconds, "
  109. << "which is " << (NumOfResults) / (MaxTime / 10) << " results per second";
  110. break;
  111.  
  112. case 't':
  113. X = Y = 0;
  114. cout << "Enter the maximum X value: ";
  115. cin >> Xmax;
  116. cout << "\nEnter the maximum Y value: ";
  117. cin >> Ymax;
  118. system("pause");
  119. system("cls");
  120.  
  121. // Move the mouse
  122. while (X < Xmax || Y < Ymax)
  123. {
  124. if (X < Xmax)
  125. {
  126. X++;
  127. }
  128.  
  129. if (Y < Ymax)
  130. {
  131. Y++;
  132. }
  133.  
  134. SetCursorPos(X,Y);
  135.  
  136. // Get the mouse point
  137. GetCursorPos(&MousePoint);
  138. cout << MousePoint.x << ", ";
  139. cout << MousePoint.y << " ";
  140. Sleep(10);
  141. }
  142. break;
  143.  
  144. case 'q':
  145. return 0;
  146. break;
  147.  
  148. case 'p':
  149. SaveFile.close();
  150. std::ifstream ReadFile(FileName);
  151. TempInt = InputInt = 0;
  152. X = Y = 0;
  153. char ch;
  154. /*
  155. cout << "\nRaw data:\n";
  156. while (!ReadFile.eof())
  157. {
  158. ReadFile.get(ch[2]);
  159. cout << ch[2];
  160. }
  161. ReadFile.close();
  162. ReadFile.open(FileName, ios::in);*/
  163.  
  164. while(!ReadFile.eof())
  165. {
  166. Sleep(10);
  167. ReadFile.get(ch);
  168. TempInt++;
  169. switch (TempInt)
  170. {
  171.  
  172. case 1:
  173. InputInt = atoi(&ch) * 1000;
  174. break;
  175.  
  176. case 2:
  177. InputInt += atoi(&ch) * 100;
  178. break;
  179.  
  180. case 3:
  181. InputInt += atoi(&ch) * 10;
  182. break;
  183.  
  184. case 4:
  185. InputInt += atoi(&ch);
  186.  
  187. TempInt = 0;
  188. if (SetX)
  189. {
  190. SetX = FALSE;
  191. SetY = TRUE;
  192. X = InputInt;
  193. cout << X << endl;
  194. }
  195. else if (SetY)
  196. {
  197. Y = InputInt;
  198. SetX = TRUE;
  199. SetY = FALSE;
  200. InputInt = 0;
  201. cout << Y << endl;
  202. SetCursorPos(X, Y);
  203. }
  204. }
  205. }
  206. ReadFile.close();
  207. } // End switch
  208.  
  209. /*for (TempInt = 0; TempInt < 256; TempInt++)
  210. {
  211. FileName[TempInt] = NULL;
  212. }
  213. */
  214. cout << "\nType 'r' to record, 'q' to quit, 't' to test, or 'p' to play";
  215. cin >> Action;
  216. } // End While
  217. return 0;
  218. }

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,374
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: macro building program help

 
0
  #2
Dec 27th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: macro building program help

 
1
  #3
Dec 28th, 2007
Voila:
  1. POINT MousePoint;
  2. int X = 0;
  3. int Y = 0;
  4. int MaxTime = 0;
  5. int Counter = 0;
  6. int NumOfResults = 0;
  7. int Xmax, Ymax = 0;
  8. int InputNumStr = 0;
  9. char Action = 'a';
  10. int TempInt, InputInt = 0;
  11. char FileName[256] = "AAAAAAAAAAAAAAAAAAA";
  12. char TempStr[256] = "AAAAAAAAAAAAAAAAAAA";
  13. BOOL SetX = TRUE, SetY = FALSE;
  14.  
  15. #include <windows.h>
  16. #include <iostream>
  17. #include <fstream>
  18. #include <cstring>
  19. #include "Macro.h"
  20.  
  21. using namespace std;
  22. int main(int argc, char* argv[])
  23. {
  24. cout << "MacroBuilder V. 1.0" << endl;
  25. cout << "\nEnter the name of the macro: ";
  26. cin >> FileName;
  27. strcat(FileName, ".txt");
  28.  
  29. std::ofstream SaveFile(FileName);
  30. SaveFile.close();
  31. cout << "Type 'r' to record, 'q' to quit, 't' to test, or 'p' to play";
  32. cin >> Action;
  33.  
  34. while ( Action != 'q' )
  35. {
  36.  
  37. switch ( Action )
  38. {
  39. case 'r':
  40. MaxTime = 0;
  41. Counter = 0;
  42. NumOfResults = 0;
  43. cout << "Enter the max time of the macro in seconds: ";
  44. cin >> MaxTime;
  45. MaxTime = MaxTime * 10;
  46. cout << "\nPress escape to stop recording\n";
  47. system("pause");
  48. system("cls");
  49. while ( MaxTime > Counter )
  50. {
  51. GetCursorPos(&MousePoint);
  52. if ( MousePoint.x < 10 )
  53. {
  54. std::ofstream SaveFile(FileName, ios::app);
  55. SaveFile << "000" << MousePoint.x;
  56. SaveFile.close();
  57. cout << "\nX: 000" << MousePoint.x;
  58. }
  59. else if ( MousePoint.x < 100 )
  60. {
  61. std::ofstream SaveFile(FileName, ios::app);
  62. SaveFile << "00" << MousePoint.x;
  63. SaveFile.close();
  64. cout << "\nX: 00" << MousePoint.x;
  65. }
  66. else if ( MousePoint.x < 1000 )
  67. {
  68. std::ofstream SaveFile(FileName, ios::app);
  69. SaveFile << "0" << MousePoint.x;
  70. SaveFile.close();
  71. cout << "\nX: 0" << MousePoint.x;
  72. }
  73. else if ( MousePoint.x > 1000 )
  74. {
  75. std::ofstream SaveFile(FileName, ios::app);
  76. SaveFile << "" << MousePoint.x;
  77. SaveFile.close();
  78. cout << "\nX: " << MousePoint.x;
  79. }
  80.  
  81. if ( MousePoint.y < 10 )
  82. {
  83. std::ofstream SaveFile(FileName, ios::app);
  84. SaveFile << "000" << MousePoint.y;
  85. SaveFile.close();
  86. cout << " Y: 000" << MousePoint.y;
  87. }
  88. else if ( MousePoint.y < 100 )
  89. {
  90. std::ofstream SaveFile(FileName, ios::app);
  91. SaveFile << "00" << MousePoint.y;
  92. SaveFile.close();
  93. cout << " Y: 00" << MousePoint.y;
  94. }
  95. else if ( MousePoint.y < 1000 )
  96. {
  97. std::ofstream SaveFile(FileName, ios::app);
  98. SaveFile << "0" << MousePoint.y;
  99. SaveFile.close();
  100. cout << " Y: 0" << MousePoint.y;
  101. }
  102.  
  103. NumOfResults++;
  104. Sleep(10);
  105. Counter++;
  106. }
  107. cout << "\n\nDisplayed " << NumOfResults << " in " << (MaxTime / 10) << " seconds, "
  108. << "which is " << (NumOfResults) / (MaxTime / 10) << " results per second";
  109. break;
  110.  
  111. case 't':
  112. X = Y = 0;
  113. cout << "Enter the maximum X value: ";
  114. cin >> Xmax;
  115. cout << "\nEnter the maximum Y value: ";
  116. cin >> Ymax;
  117. system("pause");
  118. system("cls");
  119.  
  120. // Move the mouse
  121. while ( X < Xmax || Y < Ymax )
  122. {
  123. if ( X < Xmax )
  124. {
  125. X++;
  126. }
  127.  
  128. if ( Y < Ymax )
  129. {
  130. Y++;
  131. }
  132.  
  133. SetCursorPos(X,Y);
  134.  
  135. // Get the mouse point
  136. GetCursorPos(&MousePoint);
  137. cout << MousePoint.x << ", ";
  138. cout << MousePoint.y << " ";
  139. Sleep(10);
  140. }
  141. break;
  142.  
  143. case 'q':
  144. return 0;
  145. break;
  146.  
  147. case 'p':
  148. SaveFile.close();
  149. std::ifstream ReadFile(FileName);
  150. TempInt = InputInt = 0;
  151. X = Y = 0;
  152. char ch;
  153. /*
  154. cout << "\nRaw data:\n";
  155. while (!ReadFile.eof())
  156. {
  157. ReadFile.get(ch[2]);
  158. cout << ch[2];
  159. }
  160. ReadFile.close();
  161. ReadFile.open(FileName, ios::in);*/
  162.  
  163. while ( !ReadFile.eof() )
  164. {
  165. Sleep(10);
  166. ReadFile.get(ch);
  167. TempInt++;
  168. switch ( TempInt )
  169. {
  170.  
  171. case 1:
  172. InputInt = atoi(&ch) * 1000;
  173. break;
  174.  
  175. case 2:
  176. InputInt += atoi(&ch) * 100;
  177. break;
  178.  
  179. case 3:
  180. InputInt += atoi(&ch) * 10;
  181. break;
  182.  
  183. case 4:
  184. InputInt += atoi(&ch);
  185.  
  186. TempInt = 0;
  187. if ( SetX )
  188. {
  189. SetX = FALSE;
  190. SetY = TRUE;
  191. X = InputInt;
  192. cout << X << endl;
  193. }
  194. else if ( SetY )
  195. {
  196. Y = InputInt;
  197. SetX = TRUE;
  198. SetY = FALSE;
  199. InputInt = 0;
  200. cout << Y << endl;
  201. SetCursorPos(X, Y);
  202. }
  203. }
  204. }
  205. ReadFile.close();
  206. } // End switch
  207.  
  208. /*for (TempInt = 0; TempInt < 256; TempInt++)
  209. {
  210. FileName[TempInt] = NULL;
  211. }
  212. */
  213. cout << "\nType 'r' to record, 'q' to quit, 't' to test, or 'p' to play";
  214. cin >> Action;
  215. } // End While
  216. return 0;
  217. }
Behold the power of copy, paste, a decent code editor, copy, paste, and post.
"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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: macro building program help

 
0
  #4
Dec 28th, 2007
>but now i have no idea how to do mouse clicks or keyboard input.
Go the msdn website, it should be well documented.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC