Ok here ya go Gape, this will display the mouse co-ordinates when you move the mouse and if a button has been pressed it will display which button. This assumes a 3 button mouse.
Press 'q' to quit.
Check out the MOUSE_EVENT_RECORD in your docs for all the messages you can recieve.
Code:
#include <stdio.h>
#include <windows.h>
void process_mouse( INPUT_RECORD *ir_ptr );
int main( void )
{
HANDLE hStdout, hStdin;
INPUT_RECORD ir;
UINT num;
hStdout = GetStdHandle( STD_OUTPUT_HANDLE ); // not used
hStdin = GetStdHandle( STD_INPUT_HANDLE );
while( ReadConsoleInput( hStdin, &ir, 1, &num ) )
{
switch( ir.EventType )
{
case MOUSE_EVENT: process_mouse( &ir );
break;
case KEY_EVENT: if( ir.Event.KeyEvent.uChar.AsciiChar == 'q' )
{
return 0; // quit program
}
break;
}
}
return 0;
}
void process_mouse( INPUT_RECORD *ir_ptr )
{
switch( ir_ptr->Event.MouseEvent.dwButtonState )
{
case FROM_LEFT_1ST_BUTTON_PRESSED :
printf( "\nButton1 pressed\n" );
break;
case RIGHTMOST_BUTTON_PRESSED :
printf( "\nButton2 pressed\n" );
break;
case FROM_LEFT_2ND_BUTTON_PRESSED :
printf( "\nMiddle button pressed\n" );
break;
}
switch( ir_ptr->Event.MouseEvent.dwEventFlags )
{
case MOUSE_MOVED : // print mouse co-ordinates
printf( "\nMouse is at %d %d\n",
ir_ptr->Event.MouseEvent.dwMousePosition.X,
ir_ptr->Event.MouseEvent.dwMousePosition.Y
);
break;
}
}