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
|
#include <iostream>
#include <windows.h>
#include <winable.h> /* Dev-C++ specific */
using namespace std;
/* This is a function to simplify usage of sending keys */
void GenerateKey(int vk, BOOL bExtended) {
KEYBDINPUT kb = {0};
INPUT Input = {0};
/* Generate a "key down" */
if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
/* Generate a "key up" */
ZeroMemory(&kb, sizeof(KEYBDINPUT));
ZeroMemory(&Input, sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
return;
}
void TypeText(char String[]) {
/* You could filter text in here if you wanted :) */
for (int x = 0; String[x] != 0; x++) { GenerateKey(String[x], FALSE); }
}
void Run(char *app) {
std::string command = "start ";
command += app;
system(command.c_str());
}
int main() {
/*Run("notepad.exe");*/
system("start c:\\Windows\\System32\\notepad.exe");
/* HWND = "Window Handle" */
HWND GameWindow = FindWindow(0, "Untitled - Notepad");
Sleep( 1000 );
SetWindowPos(GameWindow,
HWND_TOP,
0,
0,
0, 0, // Ignores size arguments.
SWP_NOSIZE);
/*
SetForegroundWindow will give the window focus for the
keyboard/mouse! In other words, you don't have to have
the game opened upfront in order to emulate key/mouse
presses, it's very helpful if it's a game that runs
in fullscreen mode, like StarCraft: Brood War does
*/
SetForegroundWindow(GameWindow);
for ( int x = 0; x < 10; x++ ) {
GenerateKey(VK_CAPITAL, TRUE);
GenerateKey('K', FALSE);
GenerateKey(VK_CAPITAL, FALSE);
TypeText("EYSTOKES ARE SENT IN A ROW");
GenerateKey(0x3A, FALSE); /* period key */
GenerateKey(0x0D, FALSE); /* enter key */
}
return 0;
}
|