Finding the Cursor Position

Determining the position of the cursor is vitally important if you intend to enable mouse support in your game. There is a simple API call that will allow you do this with ease.

Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long

Type PointAPI
x As Long
y As Long
End Type

Ok, it's a little more than just an API call, you also need to declare a new type, PointAPI, to go along with it. If you pass a variable of PointAPI type to the GetCursorPos function, it will fill the variable with the coordinates of the cursor. You can then retrieve this data at your leisure!

Calling this function during a mouse click or double click (ie. the Click and DblClick events of a form) is quite useful, you can then check if the cursor was over a clickable element of your game, like a button, and respond accordingly.

This concept is fairly simple, so I've just made my Cursor.BAS Module available for download. It contains everything you'll need to add simple mouse support to your game.