Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

EDIT

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.

NOTE

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

share|improve this answer

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"
    Add
      Separator
      ToolButton
        Icon MI_ICON_LINE
        Cursor MI_CURSOR_CROSSHAIR
        DrawMode DM_CUSTOM_LINE
        Calling LineTool
    Show
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
share|improve this answer
    
Great example :) –  kinkajou Nov 25 '11 at 3:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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