Sat Jan 26, 2013 9:03 pm
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HANDLE hIn;
HANDLE hOut;
COORD KeyWhere;
COORD LoopWhere;
COORD EndWhere;
bool Continue = TRUE;
DWORD EventCount;
int LoopCount = 0;
int KeyEvents = 0;
INPUT_RECORD InRec;
DWORD NumRead;
unsigned char HoldKey;
hIn = GetStdHandle(STD_INPUT_HANDLE);
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
cout << "Key Events : " << flush; // SHOW no. of ENTERY " Key Events "
KeyWhere.X = 15;
KeyWhere.Y = 0;
LoopWhere.X = 0;
LoopWhere.Y = 1;
EndWhere.X = 0;
EndWhere.Y = 2;
//////////////////// FIRST LOOP ///////////////////////////////////////////////
while (Continue)
{
SetConsoleCursorPosition(hOut,
LoopWhere);
cout << LoopCount++ << " " << flush;
Sleep(100); // To slow it down!!
cout<<EventCount<<endl;
GetNumberOfConsoleInputEvents(hIn,&EventCount);
//EventCount "DWORD" always start with "SAME NUMBER"
///////////////////// SECOND LOOP /////////////////////////////////////////////
while (EventCount > 0)
{
ReadConsoleInput(hIn,&InRec,1,&NumRead); //why?
if (InRec.EventType == KEY_EVENT ) // if event BY key
{
if (InRec.Event.KeyEvent.bKeyDown)//
{
cout<<"I am here"<<endl;
HoldKey = InRec.Event.KeyEvent.uChar.AsciiChar;
}
else
{
cout<<"Don't Play with me "<<flush<<endl;
++KeyEvents;
SetConsoleCursorPosition(hOut,
KeyWhere);
cout << KeyEvents << flush;// SHOW no. of ENTERY "keyEvents"
LoopCount = 0;
if (HoldKey =='x'|| InRec.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED ) //why?
{
cout<<"I am in the hill"<<endl;
cout<<"NO ONO "<<endl;
SetConsoleCursorPosition(hOut,EndWhere);
cout << "Exiting..." << endl;
Continue = FALSE;
}
}//END OF THE "else"
}//END OF THE FIRST "if-condition"
GetNumberOfConsoleInputEvents(hIn,&EventCount);
}// END OF THE SECOND LOOP
}//END OF THE FIRST LOOP
return 0;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.