Thread: Mouse Input

  1. #1
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227

    Mouse Input

    Hi,
    I am trying to make a game where your unit will move to where your mouse is on the screen. I read the MSDN page about console mouse input and I have this code so far:
    Code:
    ENABLE_MOUSE_INPUT;
    INPUT_RECORD MOUSE_EVENT_RECORD;
    COORD dwWritePosition;
    What I wanted to know was, isnt the COORD statement supposed to record the coordinates of the mouse, and if it does how do you retrieve the coordinates?
    Thanks
    Keyboard Not Found! Press any key to continue. . .

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Look in to the SetConsoleMode function at msdn.
    Then check out INPUT_RECORD and that should give you a good start on using everything.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    just pass an INPUT_RECORD variable into the ReadConsoleInput() function - if the EventType == KEY_EVENT, the mouse position will be in the INPUT_RECORD::Event.MouseEvent.dwMousePosition COORD.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    err...umm....could i get a quick example?
    Keyboard Not Found! Press any key to continue. . .

  5. #5
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    The coordinates are stored in the INPUT_RECORD structure.
    Code:
     
    INPUT_RECORD myinput_record;
    DWORD num;
     
    ReadConsoleInput(hStdin,&myinput_record,1,&num);
     
    myinput_record.Event.MouseEvent.dwMousePosition.X
    myinput_record.Event.MouseEvent.dwMousePosition.Y
    Here is a short example
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
     
    int main(void)
    {
    HANDLE hStdin,hStdout;
    hStdin=GetStdHandle(STD_INPUT_HANDLE);
    hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD num;
    INPUT_RECORD inputrecord;
    COORD location;
     
    location.X=0;
    location.Y=0;
     
    while(1)
    {
     
      ReadConsoleInput(hStdin,&inputrecord,1,&num);
     
    	switch(inputrecord.EventType)
    	{
    	case MOUSE_EVENT: 
     
    	  SetConsoleCursorPosition(hStdout,location);
    	  cout<<"mouse_position ";
    	  cout<<inputrecord.Event.MouseEvent.dwMousePosition.X;
    	  cout<<" "<<inputrecord.Event.MouseEvent.dwMousePosition.Y<<"		   \n";
     
    	  break;
    	}
    }
     
    return 0;
    }
    Last edited by manofsteel972; 10-17-2004 at 04:29 AM. Reason: clean up so it doesn't scroll
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  6. #6
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    Thanks a buttload man!!!
    Keyboard Not Found! Press any key to continue. . .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 10:52 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Mouse Input
    By bumfluff in forum C++ Programming
    Replies: 7
    Last Post: 11-11-2005, 01:23 AM
  4. Making a mouse hover button, API style
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2004, 06:17 AM
  5. Win32 Console App- Mouse input
    By Trauts in forum Windows Programming
    Replies: 2
    Last Post: 04-29-2003, 11:32 AM