Computer Science Canada

Mouse control

Author:  Raugrist [ Tue Apr 13, 2004 4:07 pm ]
Post subject:  Mouse control

Does anybody have any idea how I could make a program that controls the user's mouse and possibly simulate mouse clicks? You know how in a FPS when you move the mouse around to aim, the program understands that you moved the mouse in some direction, takes the necessary steps and then moves the mouse back (so you don't run into the edge of the screen).

How could I do that?

Author:  wtd [ Tue Apr 13, 2004 5:41 pm ]
Post subject: 

It's entirely dependent on what environment you're programming in. Is it an X Windows (Linux, FreeBSD, Solaris, etc.) environment, a Windows environment, or within the context of .NET?

I'd reccomend siccing Google on this problem. Smile

Author:  Raugrist [ Tue Apr 13, 2004 7:45 pm ]
Post subject: 

I was thinking windows, because I only just started Linux and the school computers are still on windows. But yeah, I guess google will be the way to go.

Author:  scryed [ Wed Apr 14, 2004 11:46 am ]
Post subject: 

If you are using MFC then just go to the class wizard, you will see events like WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE. If you map a message to these then Windows will pass in a CPoint object.

If you are doing it from scratch it is a little harder but the messages are the same.

Author:  Catalyst [ Wed Apr 14, 2004 2:05 pm ]
Post subject: 

you could either check for the message in ur windows message loop
code:

case WM_MOUSEMOVE:
 {

     mouseX =(double) LOWORD(lParam); 
     mouseY =(double) HIWORD(lParam); 
}

// these are button states

   case WM_LBUTTONDOWN:                     
   case WM_LBUTTONUP:                     
   case WM_MBUTTONDOWN:                     
   case WM_MBUTTONUP:                     
    case WM_RBUTTONDOWN:                     
   case WM_RBUTTONUP:       

// etc ...



or you could access the mouse directly using the get cursor function (this doesnt always work well tho, in my experience)

code:

POINT point;
GetCursorPos(point)
mouseX=point.x;
mouseY=point.y;


There are probably some conversion to do there tho

heres an msdn link for that
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/getcursorpos.asp


: