# onClientClick (Client)

> Fired when a mouse button is pressed or released while the cursor is showing.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Client
- **Category**: Keyboard
- **URL**: https://wiki.mymp.gg/en/onClientClick

## Syntax

```lua
addEventHandler("onClientClick", root, function(string button, string state, float absoluteX, float absoluteY, float worldX, worldY, worldZ, element|false clickedElement) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `button` | `string` | `"left"`, `"middle"` or `"right"`. |
| `state` | `string` | `"down"` on press, `"up"` on release. |
| `absoluteX` | `float` | The cursor's horizontal position in pixels. |
| `absoluteY` | `float` | The cursor's vertical position in pixels. |
| `worldX, worldY, worldZ` | `float` | The world point under the cursor where the line of sight hits something, or the point 300 units ahead when it hits nothing. |
| `clickedElement` | `element\|false` | The element hit, or `false` if there is no element there. |

## Source

The root element (`root`).

## Example

```lua
addEventHandler("onClientClick", root, function(button, state, x, y, wx, wy, wz, clicked)
    if button == "left" and state == "down" and clicked then
        outputDebugString("Clicked a " .. getElementType(clicked))
    end
end)
```

## See also

- [onClientDoubleClick (Client)](https://wiki.mymp.gg/en/onClientDoubleClick.md): Fired when a mouse button is pressed twice in a row while the cursor is showing.
- [showCursor (Client)](https://wiki.mymp.gg/en/showCursor.md): Shows or hides the mouse cursor for this resource.
- [getCursorPosition (Client)](https://wiki.mymp.gg/en/getCursorPosition.md): Reads where the cursor is on the screen and the world point it points at.
