Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <Windows.h>
  3.  
  4. #define KeyDown(Key) (GetAsyncKeyState(Key) & 0x8000)
  5.  
  6. inline bool press(INPUT *kbInput, bool down)
  7. {
  8. kbInput->ki.dwFlags = KEYEVENTF_SCANCODE;
  9.  
  10. if (!down)
  11. {
  12. kbInput->ki.dwFlags |= KEYEVENTF_KEYUP;
  13. }
  14.  
  15. SendInput(1, kbInput, sizeof(INPUT));
  16.  
  17. return down;
  18. }
  19.  
  20. int main()
  21. {
  22. POINT centre, current;
  23.  
  24. bool leftDown = false, rightDown = false;
  25. bool spacedown = false;
  26. INPUT leftKey, rightKey, spacekey;
  27. ZeroMemory(&leftKey, sizeof(INPUT));
  28. ZeroMemory(&rightKey, sizeof(INPUT));
  29. ZeroMemory(&spacekey, sizeof(INPUT));
  30.  
  31. leftKey.type = rightKey.type = spacekey.type= INPUT_KEYBOARD;
  32. leftKey.ki.dwFlags = rightKey.ki.dwFlags = spacekey.ki.dwFlags = KEYEVENTF_SCANCODE;
  33.  
  34. leftKey.ki.wScan = 0x1E;
  35. rightKey.ki.wScan = 0x20;
  36. spacekey.ki.wScan = 0x39;
  37.  
  38. bool toggle = false;
  39.  
  40. while (KeyDown(VK_RETURN) == NULL)
  41. {
  42. Sleep(250);
  43. }
  44.  
  45. GetCursorPos(&centre);
  46.  
  47. while (KeyDown(VK_END) == NULL)
  48. {
  49. GetCursorPos(&current);
  50.  
  51.  
  52. if (KeyDown(VK_MBUTTON) != NULL) //TOGGLE KEY
  53. {
  54. toggle = !toggle;
  55. Sleep(200);
  56. }
  57.  
  58. if (KeyDown(0x2D) != NULL || toggle) //HOTKEY or TOGGLE ACTIVATED
  59. {
  60.  
  61.  
  62.  
  63. if (current.x < centre.x && !leftDown) //walk left (stop moving right first)
  64. {
  65. if (rightDown)
  66. {
  67. rightDown = press(&rightKey, false);
  68. }
  69. leftDown = press(&leftKey, true);
  70. }
  71. else if (current.x > centre.x && !rightDown) //walk right (stop moving left first)
  72. {
  73. if (leftDown)
  74. {
  75. leftDown = press(&leftKey, false);
  76. }
  77. rightDown = press(&rightKey, true);
  78. }
  79. }
  80. else
  81. {
  82. if (leftDown)
  83. leftDown = press(&leftKey, false);
  84. if (rightDown)
  85. rightDown = press(&rightKey, false);
  86.  
  87. }
  88.  
  89. Sleep(5);
  90.  
  91. }
  92.  
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement