# onClientKey (Client)

> Fired when a key or mouse button is pressed or released. Cancelling the event stops that key's binds and, on a press, hides the key from the game while it is held.

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

## Syntax

```lua
addEventHandler("onClientKey", root, function(string button, bool pressOrRelease) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `button` | `string` | The key's name, as `bindKey` uses it. |
| `pressOrRelease` | `bool` | `true` on press, `false` on release. |

## Source

The root element (`root`).

When it is cancelled, the server is not told about the key either, so server binds do not fire. The mouse wheel arrives as `mouse_wheel_up` or `mouse_wheel_down`, pressed and released right away.

## Example

```lua
addEventHandler("onClientKey", root, function(button, pressed)
    if button == "f" and pressed and isCursorShowing() then
        cancelEvent()
    end
end)
```

## See also

- [bindKey (Shared)](https://wiki.mymp.gg/en/bindKey.md): Binds a key to a function or a command. The function runs when the key is pressed, released or both.
- [getKeyState (Client)](https://wiki.mymp.gg/en/getKeyState.md): Tells whether a key is held down right now.
- [cancelEvent (Shared)](https://wiki.mymp.gg/en/cancelEvent.md): Marks the running event as cancelled. What cancelling prevents depends on the event.
