Simulating keyboard presses from a string

I have attempted to make a function to use keybd_event(), however, when i use the function, only the first 4 letters of the string are typed.

My header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <windows.h>

void kout(char * kp)
{

	int length=sizeof(kp);
	
	for(int i=0;i<length;i++)
	{
		keybd_event(VkKeyScan(kp[i]),0,0,0); //depress
		keybd_event(VkKeyScan(kp[i]),0, KEYEVENTF_KEYUP,0); // release!
	Sleep( 100 );
	}
	

	

}


My main.cpp :

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
#include<windows.h>
#include "kbd_keys.h"
void kout(char*);

int APIENTRY WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                    int       nCmdShow)

  {													// begin WinMain curly brace 
    BOOL ttog=TRUE;
	BOOL key=TRUE;
	Sleep( 3000 );
	
	
	for( ; ; )
	{															// begin infinite for curly brace
	
START:
	Sleep( 5 );	
	if(GetAsyncKeyState( 0x7B ) ) // if F9 is pressed, toggle text
	{
		if(ttog==TRUE)
		{
			ttog=FALSE;
		}
		else
		{
			ttog=TRUE;
		}
	}
	if(GetAsyncKeyState( 0x79 ) ) // press F10 to close the program
	{
		return 0;
	}
	if(GetAsyncKeyState( 0x7B ) ) // if F12 is pressed, START
	{																//begin if F12
	
		while(ttog==TRUE)
	{																	//begin while
		
		
		if(GetAsyncKeyState( 0x7A )) // if F11 is pressed, STOP
			{
			goto START;
			}	

char* mystring = "There is no Caled.";
	kout(mystring);


	}																//end while
	
}																	//end F12
	}																//end infinite for
}//end main curly brace


It will only print ther, any help would be appreciated.
sizeof(kp) returns the size of a pointer (4 bytes), try using strlen
thank you for pointing out my error, i appreciate the help greatly! I really did not realize there were two things like that!
Topic archived. No new replies allowed.