1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <windows.h>
#include <iostream>
#pragma comment(lib, "Winmm.lib")
// Adjust for timing:
const static DWORD TO_TOP_FROM_START = 1775; //time needed to go from starting position to the top of the grid.
const static DWORD TO_EDGE_FROM_MIDDLE = 1895; // time needed to go from start position to left side of grid.
const static DWORD LONG_WAYS = 3937; // time needed to go horizontally accros the entire grid but one block.
const static DWORD SHORT_WAYS = 1950; // time needed to go vertically accros the entire grid.
using namespace std;
bool isEnterPressed()
// Returns: True if ENTER has been pressed since
// last call. Otherwise, False.
// Note: You do not need to be focused on the output
// terminal for the key to be recongnized.
{
int res = ::GetAsyncKeyState(VK_RETURN);
return res < 0;
}
void waitTillSpaceIsPressed()
// Description: Waits until SPACE is pressed.
// Note: You do not need to be focused on the output
// terminal for the key to be recongnized.
{
cout << "Press Space To Continue (you do not need to be focused on this window)...";
int res;
do{
res = ::GetAsyncKeyState(VK_SPACE);
}while (!( res < 0 ));
}
int snake()
// How to use: Call timeBeginPeriod(1) before snake(),
// and call timeEndPeriod(1) after snake().
// Description: Moves the snake around the entire grid.
// Starts at top left and weaves its way down,
// then loops back to the top on the right side.
// Returns: Nothing.
// Warning: Press ENTER to exit this function!
// Otherwise, timeBeginPeriod will be called
// without timeEndPeriod, thus ending civilization
// as we know it...
{
cout << "+-----------------------------------+" << endl;
cout << "| Press ENTER At Anytime To Exit. |" << endl;
cout << "| |" << endl;
cout << "| Note: Don't Exit Any Other Way! |" << endl;
cout << "+-----------------------------------+" << endl << endl;
Sleep(TO_TOP_FROM_START);
keybd_event(VK_LEFT,0x25,0 , 0); // Left Arrow Press
keybd_event(VK_LEFT,0x25,KEYEVENTF_KEYUP,0); // Left Arrow Release
Sleep(TO_EDGE_FROM_MIDDLE);
for(int j = 0; j < 410; j++)
{
for(int i = 0; i < 15; i++)
{
cout << j << " X " << i << endl;
keybd_event(VK_DOWN,0x28,0 , 0); // Down Arrow Press
keybd_event(VK_DOWN,0x28,KEYEVENTF_KEYUP,0); // Down Arrow Release
keybd_event(VK_RIGHT,0x27,0 , 0); // Right Arrow Press
keybd_event(VK_RIGHT,0x27,KEYEVENTF_KEYUP,0); // Right Arrow Release
if(isEnterPressed())
return 0;
Sleep(LONG_WAYS);
keybd_event(VK_DOWN,0x28,0 , 0); // Down Arrow Press
keybd_event(VK_DOWN,0x28,KEYEVENTF_KEYUP,0); // Down Arrow Release
keybd_event(VK_LEFT,0x25,0 , 0); // Left Arrow Press
keybd_event(VK_LEFT,0x25,KEYEVENTF_KEYUP,0); // Left Arrow Release
if(isEnterPressed())
return 0;
Sleep(LONG_WAYS);
}
keybd_event(VK_DOWN,0x28,0 , 0); // Down Arrow Press
keybd_event(VK_DOWN,0x28,KEYEVENTF_KEYUP,0); // Down Arrow Release
keybd_event(VK_RIGHT,0x27,0 , 0); // Right Arrow Press
keybd_event(VK_RIGHT,0x27,KEYEVENTF_KEYUP,0); // Right Arrow Release
if(isEnterPressed())
return 0;
Sleep(LONG_WAYS+62);
keybd_event(VK_UP,0x26,0 , 0); // Up Arrow Press
keybd_event(VK_UP,0x26,KEYEVENTF_KEYUP,0); // Up Arrow Release
if(isEnterPressed())
return 0;
Sleep(SHORT_WAYS);
keybd_event(VK_LEFT,0x25,0 , 0); // Left Arrow Press
keybd_event(VK_LEFT,0x25,KEYEVENTF_KEYUP,0); // Left Arrow Release
if(isEnterPressed())
return 0;
Sleep(LONG_WAYS+62);
}
return 0;
}
int main()
{
cout << "First, go to the snake game at http://apps.facebook.com/mindjolt/games/snake." << endl << endl;
cout << "Then, focus on the game and press SPACE to start the game and this program." << endl <<endl;
waitTillSpaceIsPressed();
cout << endl << endl;
timeBeginPeriod(1);
snake();
timeEndPeriod(1);
return 0;
}
|