-
mouse in msvc( FAO Gape)
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;
}
}
-
-
Code doesn´t work
I tried this code but it did not work. The compiler said it could not convert paramter 4 from 'unsigned int *' to 'unsigned long *' in the following line:
"while( ReadConsoleInput( hStdin, &ir, 1, &num ) )"
-
You must declare variable num as the DWORD.
-
Uh-huh...
...and this is done how? (what´s a DWORD, anyway?)
There´s lots of stuff in that code which I do not really understand, would you mind explaining som of it?
-
DWORD stands for "unsigned long". What don't you understand?
-
Pretty much...
...this part:
Code:
HANDLE hStdout, hStdin;
INPUT_RECORD ir;
UINT num;
hStdout = GetStdHandle( STD_OUTPUT_HANDLE ); // not used
hStdin = GetStdHandle( STD_INPUT_HANDLE );
Like, what does "HANDLE" and its variables(?) mean and what is "UINT num". The other stuff is functions included in one of the libraries, right? (like GetStdHandle(...))
But what do they do?