Program writing words/text

Hello!
So I am trying to make program, that could go to a window (for example browser or text document) and write some text there. It sounds simple, so I tried to experiment, then googled for couple of hours. I know how to set position of cursor, so I can run program, make the window on top (for that part I use sleep and do it manually), move cursor to place where I want to write, simulate mouse click. And then.. I can do keystroke simulation, but I need like 100 symbols (including letters, numbers, space and etc.) and some numbers I would want to change. Like using cycle and everytime writing bigger number. And also I would want to take an answer to my program. Like copy a number from a certain place in screen. I can move cursor again, highlight it using double click. But then what?
If you have any advices please tell me. I'm newbie so I would prefer it as simple as possible. Like one command or something.

My program looks something like this:
1
2
3
4
5
  Sleep(5000);
  SetCursorPos(300, 300);
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  // type some random text 


P.S. I don't know if I should put it in beginners or windows programming section, but because it looks so simple I will put it into begginers. Sorry if I make mistake and please tell me if I need to put it to windows programming one. And if it's possible to do that too.
Last edited on
Why not just set it to a string? And have the program write exactly the phrase you are looking for?

Instead of having it input keyboard letters one by one to write the word "hello" you can make it just do the entire word Hello instantly.

Also instead of having your mouse move on the screen to open say notepad, just have your system call notepad and open it.
This will get your notepad open and hit enter to clear the message. I have to go to work so couldn't finish the rest atm.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#define WINVER 0x0500
#include <iostream>
#include <Windows.h>

using namespace std;

int main(){
    INPUT ip;
    system( "notepad.exe myfile.txt" );
    Sleep(2000);
    ip.ki.wVk = 0x0D;
    ip.ki.dwFlags = 0;
    SendInput(1, &ip, sizeof(INPUT));
}
Oh, okay then. I know I can use string, but the thing is - how should I write it? Like ofstream, cout and stuff like that will put it out somewhere (console screen, some text file etc.), but if I want to write it to selected area, like I could do by pressing my keyboard keys. How to do that? The whole string thingy. Is there like different command (like cout or something) to do that?
By the way, thanks for the code. It's pretty interesting and usefull. It will save some time
Topic archived. No new replies allowed.