Key Event Problem

I am trying to make a program that can type a string into another window.
I have gotten it to the point that it can type the string, just not correctly.
It will type random numbers and not the given string.
The key event uses ASCII code for the arguments, and I don't see anything wrong with my numbers.
Here is the code I have so far. Any help will be appreciated.

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
#include "stdafx.h"
#include <iostream>
#include <windows.h>

using namespace std;

void Type(string,string, int);

int main()
{
	for(int i = 1; i < 25; i++)
	{
		string mes("abc");
		string sub("a b c a b c a b c");
		Type(sub,mes,i);
		Sleep(10000);
	}
	system("pause");
	return 0;
}

void Type(string sub, string mes, int i)
{
	int sublength = sub.length();
	for(int a = 0; a < sublength; a++)
	{
		if(sub[a] == 'a')
		{
			keybd_event(97, 0, 0, 0);
		}
		else if(sub[a] == 'b')
		{
			keybd_event(98, 0, 0, 0);
		}
		else if(sub[a] == 'c')
		{
			keybd_event(99, 0, 0, 0);
		}
         }
)

Output:
1 2 3 1 2 3 1 2 3

Expexted output:
a b c a b c a b c
Last edited on
The key event uses ASCII code for the arguments, and I don't see anything wrong with my numbers.


I don't know what key event you're talking about, but kybd_event does not use ASCII codes.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304%28v=vs.85%29.aspx

This could've been answered by googling for keybd_event quite easily.
Well it works now. Thanks.
Topic archived. No new replies allowed.