0

Hey, I was just wondering what was the simplest way to "real" world type, like open wordpad and you could watch it actually typing, thanks in advance. (Hopefully the answer is not writing to file etc)

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by William Hemsworth
0

Do you meen actually emulating keypresses ?
Here is an example of how to do that:

#include<iostream>
#include<windows.h>
using namespace std;

void SendKeysWait(char *text, int interval);

int main() {
	system("start C:\\Windows\\notepad.exe");
	Sleep(1000);
	SendKeysWait("Hello world!", 30);
	cin.ignore();
	return 0;
}

void SendKeysWait(char *text, int interval) {
	int ch;
	int ch2 = -1;
	bool SHIFTDOWN = 0;
	for (int i = 0;  text[i]; i++) {
		SHIFTDOWN= 0;
		switch (text[i]) {
			case '\"':{ch = VkKeyScan('\"');ch2= VK_SHIFT; SHIFTDOWN = 1;} break;
			case '£': {ch = VkKeyScan('£');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '$': {ch = VkKeyScan('$');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '%': {ch = VkKeyScan('%');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '^': {ch = VkKeyScan('^');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '&': {ch = VkKeyScan('&');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '*': {ch = VkKeyScan('*');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '_': {ch = VkKeyScan('_');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '+': {ch = VkKeyScan('+');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '{': {ch = VkKeyScan('{');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '}': {ch = VkKeyScan('}');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '@': {ch = VkKeyScan('@');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '~': {ch = VkKeyScan('~');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '?': {ch = VkKeyScan('?');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '<': {ch = VkKeyScan('<');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '>': {ch = VkKeyScan('>');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '|': {ch = VkKeyScan('|');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case ':': {ch = VkKeyScan(':');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '!': {ch = VkKeyScan('!');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '(': {ch = VkKeyScan('(');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case ')': {ch = VkKeyScan(')');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			default:
				{
					if (text[i] >= 'A' && text[i] <= 'Z') {
						ch = VkKeyScan( text[i]);
						ch2 = VK_SHIFT;
						SHIFTDOWN = 1;
					} else ch = VkKeyScan( text[i]);
				}
		}
		if (SHIFTDOWN) keybd_event(ch2, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
		keybd_event(ch, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
		keybd_event(ch, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
		if (SHIFTDOWN) keybd_event(ch2, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
		Sleep(interval);
	}
}

I just made this work with my computer, dont know about others :P

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.