Hi.
I created a little code that reads the input of the user by mouse and by key input. I actually couldn't really find any real usefull code only after a long search on msdn. I made this code for an example, to test if it is possible to read the user his mouse and key input and still have an never-ending-loop going on, and it worked. I will use this in my big project but I guessed it may come usefull for others. It's very easy and clear code and not that spagetti code from msdn, :P. I hope it may come usefull for you too.
PHP Code:
#include <iostream>
#include <windows.h>
using namespace std;
bool Mouse_On;
KEY_EVENT_RECORD Key;
MOUSE_EVENT_RECORD Mouse;
INPUT_RECORD Record_Input;
DWORD Input_Size,
Event_Count;
int main()
{
cout<< endl<< endl<< "Click on [HERE]";
Mouse_On = false;
while ( EOF )
{
GetNumberOfConsoleInputEvents ( GetStdHandle ( STD_INPUT_HANDLE ), & Event_Count );
if ( Event_Count != 0 )
{
ReadConsoleInput ( GetStdHandle ( STD_INPUT_HANDLE ), & Record_Input, 1, & Input_Size );
if ( Record_Input.EventType == KEY_EVENT )
{
Key = Record_Input.Event.KeyEvent;
if ( Key.bKeyDown == true )
{
if ( Key.wVirtualKeyCode == VK_RIGHT )
{
cout<< endl<< endl<< "Right arrow";
}
else if ( Key.wVirtualKeyCode == VK_LEFT )
{
cout<< endl<< endl<< "Left arrow";
}
else if ( Key.wVirtualKeyCode == VK_RETURN )
{
cout<< endl<< endl<< "Enter key";
}
}
}
else if ( Record_Input.EventType == MOUSE_EVENT )
{
Mouse = Record_Input.Event.MouseEvent;
if ( Mouse.dwMousePosition.X >= 9 &&
Mouse.dwMousePosition.X <= 14 &&
Mouse.dwMousePosition.Y == 2 )
{
if ( Mouse.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED )
{
cout<< endl<< endl<< "You clicked on [HERE]";
}
else if ( Mouse_On == false )
{
cout<< endl<< endl<< "Click now on [HERE]";
Mouse_On = true;
}
}
else if ( Mouse_On == true )
{
Mouse_On = false;
}
}
}
Sleep ( 100 );
}
}