
#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#define KeyDown(Key) (GetAsyncKeyState(Key) & 0x8000)
inline bool press(INPUT *kbInput, bool down)
{
kbInput->ki.dwFlags = KEYEVENTF_SCANCODE;
if (!down)
{
kbInput->ki.dwFlags |= KEYEVENTF_KEYUP;
}
SendInput( 1, kbInput, sizeof(INPUT) );
return down;
}
int main()
{
POINT centre, current;
bool leftDown = false, rightDown = false;
INPUT leftKey, rightKey;
ZeroMemory(&leftKey, sizeof(INPUT));
ZeroMemory(&rightKey, sizeof(INPUT));
leftKey.type = rightKey.type = INPUT_KEYBOARD;
leftKey.ki.dwFlags = rightKey.ki.dwFlags = KEYEVENTF_SCANCODE;
leftKey.ki.wScan = 0x1E;
rightKey.ki.wScan = 0x20;
bool toggle = false;
puts("Please focus CS:S and close any in-game interfaces including the Steam Overlay. Press Return when ready...");
while (KeyDown(VK_RETURN) == NULL)
{
Sleep(250);
}
GetCursorPos( ¢re );
while (KeyDown(VK_END) == NULL)
{
GetCursorPos(¤t);
if (KeyDown(VK_MBUTTON) != NULL) //TOGGLE KEY
{
toggle = !toggle;
Sleep(200);
}
if (KeyDown( VK_F2 ) != NULL || toggle) //HOTKEY or TOGGLE ACTIVATED
{
if (current.x < centre.x && !leftDown) //walk left (stop moving right first)
{
if (rightDown)
{
rightDown = press(&rightKey, false);
}
leftDown = press( &leftKey, true );
}
else if (current.x > centre.x && !rightDown) //walk right (stop moving left first)
{
if (leftDown)
{
leftDown = press(&leftKey, false);
}
rightDown = press( &rightKey, true );
}
}
else
{
if (leftDown)
leftDown = press( &leftKey, false );
if (rightDown)
rightDown = press( &rightKey, false );
}
Sleep(10);
}
return 0;
}