Thread: Mouse Movement

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    70

    Mouse Movement

    Hey. I was wondering how to capture mouse movement. And if the mouse is clicked in a certain area...it would return a different value than any other area. Such that...
    Code:
    COORD dwCursorPosition={79,23};
    
    and then some sort of "IfMouseIsClickedIn(dwCursorPosition);
    it probably won't be that simple, but that's the idea.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    PtInRect()?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Under MFC, one solution is to add a handler for WM_MOUSEMOVE.

    Kuphryn

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    I'm not going to ask anyone to explain everything to me, but could you tell me the functions...maybe some links to MSDN...I can understand MSDN fine once i actually find what i want. Or some tutorials?

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    As Kuphryn has mentioned WM_MOUSEMOVE is one message you could take a look at. Other mouse messages of interest in this regard are WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUUTONDOWN, WM_MBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP.

    You need to have some familiarity with message processing, though. And don't forget to check out Adrianxw's 'PtinRect' for when you have some mouse coordinates to work with from the above messages.

    There is also GetCursorPos, too.

    A search of this board and msdn on any of these should get you started.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    Ok, I've been fulling around for awhile...and this is what I got. I want it to loop and once you click on the 'X' it will quit...what is actually going on here? and how can i fix it please.

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    main(){
    	SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ENABLE_MOUSE_INPUT);
    	bool Continue=1;
    	INPUT_RECORD InputRecord;
    	CONSOLE_SCREEN_BUFFER_INFO csbi;
    	COORD dwCursorPosition={79,23};
    	DWORD Events=0;
    	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),dwCursorPosition);
    	cout<<'x';
    	dwCursorPosition.X=0;
    	dwCursorPosition.Y=0;
    	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),dwCursorPosition);
    	while(Continue==1){
    		ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE) , &InputRecord, 1, &Events);
    		if(InputRecord.EventType == MOUSE_EVENT)
    		{
    			if(InputRecord.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){
    				GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&csbi);
    				if(csbi.dwCursorPosition.X==79 && csbi.dwCursorPosition.Y==23){
    					Continue=0;
    				}
    			}
    		}
    	}
    	return 0;
    }
    It is a tad revised now, but I'm still having problems. It is atleast accepting mouse input now.
    Last edited by Extol; 04-22-2003 at 07:26 PM.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Have you looked at

    SetCapture()

    Don't know if it is needed in console mode
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulating mouse movement in other windows
    By Wiretron in forum Windows Programming
    Replies: 11
    Last Post: 10-13-2007, 08:11 AM
  2. simple mouse movement program
    By skankles in forum Windows Programming
    Replies: 3
    Last Post: 05-27-2007, 07:54 PM
  3. Recognizing mouse movement???
    By jrkid in forum C++ Programming
    Replies: 3
    Last Post: 07-19-2004, 11:49 AM
  4. Controlling Mouse movement?
    By raum in forum Windows Programming
    Replies: 6
    Last Post: 07-02-2004, 08:46 AM
  5. Need to read mouse movement in program
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 01-03-2002, 03:15 PM