3

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.

Stev_k
6,7892 gold badges36 silver badges48 bronze badges
asked Nov 24, 2011 at 11:05

2 Answers 2

1

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.

answered Nov 24, 2011 at 11:49
1

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
answered Nov 24, 2011 at 15:44
1
  • Great example :) Commented Nov 25, 2011 at 3:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.