program to simulate keyboard presses

Hello, I have a program to simulate keyboard keypresses, and I have been fiddling with it for a while now and
can't get it to work right, it doesn't display the right output,
after the dynamically allocated char array is created,
the pointer points to ýýýý««««««««îþîþ,
and when I press F10 I get a debug assertion failed error.

The code is as follows:
HEADER FILE
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
void kcout(char* myout) {
		int length=strlen(myout);
		for( int i=0; i<length; i++)
		{
		switch(myout[i])
		{
		case '!':
		case '@':
		case '#':
		case '$':
		case '^':
		case '&':
		case '*':
		case '(':
		case ')':
		case '_':
		case '+':
		case '~':
		case '{':
		case '}':
		case '|':
		case '"':
		case ':':
		case '<':
		case '>':
		case '?':
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
		case 'G':
		case 'H':
		case 'I':
		case 'J':
		case 'K':
		case 'L':
		case 'M':
		case 'N':
		case 'O':
		case 'P':
		case 'Q':
		case 'R':
		case 'S':
		case 'T':
		case 'U':
		case 'V':
		case 'W':
		case 'X':
		case 'Y':
		case 'Z':
		case '%':
			keybd_event(VK_SHIFT,0x10,0,0); // shift depress
			keybd_event(VkKeyScan(myout[i]),0,0,0); //depress
			keybd_event(VkKeyScan(myout[i]),0, KEYEVENTF_KEYUP,0); // release!
			keybd_event(VK_SHIFT,0x10,KEYEVENTF_KEYUP,0);// shift release
			break;

		default:
			keybd_event(VkKeyScan(myout[i]),0,0,0); //depress
			keybd_event(VkKeyScan(myout[i]),0, KEYEVENTF_KEYUP,0); // release!
			break;
		}
		}
}

void ret()
{
		keybd_event(VK_RETURN,0x0D,0,0); //enter depress!
		keybd_event(VK_RETURN,0x0D, KEYEVENTF_KEYUP,0); // enter release!
}


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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include<windows.h>
#include<fstream>
#include<iomanip>
#include<time.h>
#include "kbd_keys.h"

using namespace std;
//void kout(char*); unused as of now
void ret();
void kcout(char*);
//char output[255];
char* mystring= "there is no caled.";
//int MSIZE;
//char* output=new char[MSIZE];
int a=0;
char b;
BOOL mc=TRUE;
char tmpbuf[9];
    errno_t err;
char* output=NULL;

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

  {													// begin WinMain curly brace 
    MessageBox(NULL, "F12 to begin spamming, F11 to stop, F10 to close program, edit the typeme.txt while app is not running", "REMEMBER THIS NOOB", 0);
	//check to see if typeme.txt exists
	ifstream myfile; // we use ifstream to read from the file.
	myfile.open("typeme.txt", ios::in); // open the file for reading
	Sleep( 1000 );
	if (!myfile.is_open())
	{
		MessageBox(NULL, "The text file typeme.txt failed to open, this may be due to inadequate access permissions, or your noob ass just deleted the file.. in which case, make a new typeme.txt", "MAKE A NEW TYPEME.TXT", 0);
	}
	
	for( ; ; )
	{															// begin infinite for curly brace
	
START:
	Sleep( 5 );	
	

	if(GetAsyncKeyState( 0x79 ) ) // press F10 to close the program
	{
		
		if(myfile.is_open())
		{
		myfile.close(); // close the open ifstream
		}
		if(&output!=NULL)
		{
			delete [] output;
		}
		return 0;
	}
	if(GetAsyncKeyState( 0x7B ) ) // if F12 is pressed, START
	{																//begin if F12
		while(!GetAsyncKeyState( 0x7A ))							//begin F11 while
		{
	
	
		if (myfile.is_open()&& (mc==TRUE)) // if file opened successfully read it one char at a time
	{																					
	mc=FALSE;
		if(output==NULL)
	{
		output=new char[];													//MSIZE
	}
	while(!(myfile.eof()))
	{
		
		myfile.get(b);
//		//MSIZE++;
		output[a]=b;
		a++;
	}
	
	
	myfile.seekg(0,ios::beg);
	

	
	myfile.setstate(ios::goodbit);
	

	}
if(*output!=NULL){
		kcout(output);
	ret();
		
	}
	if(!myfile.is_open())
		{
			kout(mystring);
		}
				
		if(GetAsyncKeyState( 0x7A )) // if F11 is pressed, STOP
			{
				if(myfile.is_open())
				{
				delete [] output;
				}
				goto START;
			}	
		
		}															//end while
		goto START;	
	}																	//end F12
	}																//end infinite for
}//end main curly brace 


now, i know my coding style isn't the best, but please offer suggestions for improvement

I would like to use dynamic memory allocation, but alternative approaches are welcomed suggestions.
Last edited on
i have updated my code, i added MSIZE+1 to the size paremeter of the dynamically allocated char array, after i uncommented MSIZE, and made it loop through the file once to get the size of MSIZE
then i declare the dynamically allocated char array with MSIZE as parameter, now it doesn't crash when i run it, nor does it crash when i press F11, but the output isn't right
Topic archived. No new replies allowed.