Working with Mouse Events

This sample shows how to handle mouse events, using _ITerraExplorerEvents4::OnLButtonDown() event notification as well as the IRender4::ScreenToWorld() method for translating the screen coordinate.

 

<HTML>

<b>Controlling Mouse Events Sample</b></br>

This sample shows how to monitor mouse events.</br>

 

<SCRIPT Language="VBSCRIPT">

Dim IRender4

Dim bMonitorMouse

 

sub Init()

bMonitorMouse = false

Set IRender4 = TE.interface("IRender4")

end sub

 

Sub TE_OnLButtonDown (Flags, X, Y,bHandled)

If Not bMonitorMouse Then

   Exit Sub

End If

ObjType = 63 'Monitor all object types

IRender4.ScreenToWorld X , Y , ObjType , WorldX,WorldHeight,WorldY, ObjectID

select case ObjType

case "0"

   MsgBox "Terrain coordinates: " + Chr(13)+Chr(10) + cstr(WorldX) + "/" + cstr(WorldY)

case "32"

   MsgBox "You clicked the sky"

case else

   MsgBox "You Clicked ObjectID: " + ObjectID

end select

bHandled = true 'Indicate that the client handled the event.

end sub

 

sub MonitorMouse()

If bMonitorMouse Then

   bMonitorMouse = false

   IRender4.SetMouseInputMode 0

   document.form1.Monitor_Mouse.value = "Monitor Mouse"

Else

   bMonitorMouse = true

   IRender4.SetMouseInputMode 1

   document.form1.Monitor_Mouse.value = "Stop Monitoring"

End If

end sub

</SCRIPT>

<FORM name="form1">

<INPUT type=button value="Monitor Mouse" name="Monitor_Mouse" onclick="MonitorMouse()"></br>

</FORM>

<BODY onload=Init()>

<OBJECT ID="TE" CLASSID="CLSID:3a4f9191-65a8-11d5-85c1-0001023952c1"></OBJECT>

</BODY>

 

</HTML>