Novelty scripting reference > Scripted events > OnMouseClick

OnMouseClick

This event is triggered when the user clicks a mouse button.

Remarks:

The mouse coordinates given are relative to the center of the scene. To make them relative to an object or the top left corner of scene use TransformToObjectCoord or TransformToSceneCoord respectively.


Implicit arguments

Object@ sender
Handle to an associated object; or null.

MouseButton mouseButton
Button that was clicked.

float mouseX
Horizontal cursor position.

float mouseY
Vertical cursor position.


Sample

event Sample.OnMouseClick
{
	// Get point where object was clicked  
	Vector2 Point = TransformToObjectCoord(sender, mouseX, mouseY);
	Print(Point.AsString());

	// Print the name of the button that was clicked  
	switch (mouseButton)
	{
	case MB_LEFT:
		Print("Left button");
		break;
	case MB_MIDDLE:
		Print("Middle button");
		break;
	case MB_RIGHT:
		Print("Right button");
		break;
	}
}

Back to top