다음 코드는 메모장이 열려 있을 경우 메모장에
I am cooler than you will ever be.
을 출력시켜주는 프로그램입니다.
-------------------------------------------------------------------------------------------
#include <iostream>
#include <windows.h>
#include <tchar.h>
using namespace std;
/* HWND = "Window Handle" */
HWND GameWindow = FindWindow(0, _T("제목 없음 - 메모장"));
/* 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;
}
int main() {
/*
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);
GenerateKey(VK_CAPITAL, TRUE);
GenerateKey('I', FALSE);
GenerateKey(' ', FALSE);
GenerateKey(VK_CAPITAL, TRUE);
GenerateKey('A', FALSE);
GenerateKey('M', FALSE);
GenerateKey(' ', FALSE);
GenerateKey('C', FALSE);
GenerateKey('O', FALSE);
GenerateKey('O', FALSE);
GenerateKey('L', FALSE);
GenerateKey('E', FALSE);
GenerateKey('R', FALSE);
GenerateKey(' ', FALSE);
GenerateKey('T', FALSE);
GenerateKey('H', FALSE);
GenerateKey('A', FALSE);
GenerateKey('N', FALSE);
GenerateKey(' ', FALSE);
GenerateKey('Y', FALSE);
GenerateKey('O', FALSE);
GenerateKey('U', FALSE);
GenerateKey(' ', FALSE);
GenerateKey('W', FALSE);
GenerateKey('I', FALSE);
GenerateKey('L', FALSE);
GenerateKey('L', FALSE);
GenerateKey(' ', FALSE);
GenerateKey('E', FALSE);
GenerateKey('V', FALSE);
GenerateKey('E', FALSE);
GenerateKey('R', FALSE);
GenerateKey(' ', FALSE);
GenerateKey('B', FALSE);
GenerateKey('E', FALSE);
GenerateKey('n', FALSE);
GenerateKey(' ', FALSE);
GenerateKey(0x3A, FALSE); /* period key */
GenerateKey(0x0D, FALSE); /* enter key */
return 0;
}
'c·c++ > c 프로그래밍' 카테고리의 다른 글
4칙 연산 - 간단한 계산기 (0) | 2012.08.23 |
---|---|
4원 1차 연립방정식 - 2개의 식 (0) | 2012.08.23 |
빠진 수 찾기 (0) | 2012.08.23 |
수건돌리기, 요세푸스의 문제 (0) | 2012.08.22 |
visual studio 2008에서 jpg를 읽어오고 싶은데요 (0) | 2012.08.14 |