How can I respond to mouse unclick in mapinfo using mapbasic? Is there any event triggered when the mouse in unclicked? For example at the end of drawing a line when the mouse button is released.

2 Answers 2


CommandInfo() is a useful function which retains all information pertaining to recent events in MapBasic. I cannot remember, off hand, all of the items it returns, but I'd check that for a starting point


I have just looked at this, and you need to use the CommandInfo() function thus:

 1stX = CommandInfo(CMD_INFO_X)
 1stY = CommandInfo(CMD_INFO_Y)
 lastX = CommandInfo(CMD_INFO_X2)
 lastY = CommandInfo(CMD_INFO_Y2)
  • this returns the click xy and the xy where the user releases the mouse button.


This only applies if the toolbutton was defined with a draw mode that allows dragging, e.g., DM_CUSTOM_LINE.


As far as I know it's not possible to constantly listen for a mouseup event (it's usually called mouseup, not unclick).

However you can create a custom tool which you can then use to capture mouse clicks on mapper windows. This is what Hairy is getting at in his answer.

It's not quite the same thing but it's as close as you're going to get.

Some untested example code:

Include "mapbasic.def"
Include "icons.def"

Declare Sub Main
Declare Sub LineTool

Sub Main
  Alter ButtonPad "Drawing"
        Icon MI_ICON_LINE
        DrawMode DM_CUSTOM_LINE
        Calling LineTool
End Sub

Sub LineTool
  Set Distance Units "m"
  Set Coordsys Earth

  Dim start_x, start_y, end_x, end_y as Float

  start_x = CommandInfo(CMD_INFO_X)
  start_y = CommandInfo(CMD_INFO_Y)
  end_x = CommandInfo(CMD_INFO_X2)
  end_y = CommandInfo(CMD_INFO_Y2)

  Print "Distance between those two points was: " & CartesianDistance(start_x, start_y, end_x, end_y, "m")
End Sub
  • Great example :)
    – kinkajou
    Nov 25, 2011 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.