You don't say which program you are using, so I'll use the first as an example. I started a new console project in VC and added the source file with a .c extension rather than .cpp.
To get it to compile, I had to change the "cout" statements to printf() function calls. I had to comment out the iostream include and the namespace directive, and include <stdio.h>, then I had to change the type "bool" to "boolean" It then compiled and ran.
Code:
#include <windows.h>
#include <stdio.h>
//#include <iostream>
//using namespace std;
int main()
{
HANDLE hIn;
HANDLE hOut;
COORD KeyWhere;
COORD MouseWhere;
COORD EndWhere;
boolean Continue = TRUE;
int KeyEvents = 0;
int MouseEvents = 0;
INPUT_RECORD InRec;
DWORD NumRead;
hIn = GetStdHandle(STD_INPUT_HANDLE);
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
// cout << "Key Events : " << endl;
// cout << "Mouse Events : " << flush;
printf("Key Events : \n");
printf("Mouse Events : ");
KeyWhere.X = 15;
KeyWhere.Y = 0;
MouseWhere.X = 15;
MouseWhere.Y = 1;
EndWhere.X = 0;
EndWhere.Y = 3;
while (Continue)
{
ReadConsoleInput(hIn,
&InRec,
1,
&NumRead);
switch (InRec.EventType)
{
case KEY_EVENT:
++KeyEvents;
SetConsoleCursorPosition(hOut,
KeyWhere);
// cout << KeyEvents << flush;
printf("%d",KeyEvents);
if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
{
SetConsoleCursorPosition(hOut,
EndWhere);
// cout << "Exiting..." << endl;
printf("Exiting...\n");
Continue = FALSE;
}
break;
case MOUSE_EVENT:
++MouseEvents;
SetConsoleCursorPosition(hOut,
MouseWhere);
// cout << MouseEvents << flush;
printf("%d",MouseEvents);
break;
}
}
return 0;
}
If that doesn't work, I'll need to know where it is failing and what error message you are getting.