Advertisement
Guest User

dickie

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