# Input

> Input from users: touch, keyboard and mouse controls, and gamepads.

Users interact with objects by clicking them, and with scripted vehicles, weapons and HUDs through captured controls. A script can capture movement keys and the mouse button, and read gamepad buttons and axes.

Input is not free text: for choices and typed input, use [dialogs](/features/dialog/), text boxes or [chat commands](/features/communications/).

Touch needs no permission. Controls need [`PERMISSION_TAKE_CONTROLS`](/constants/PERMISSION_TAKE_CONTROLS/); gamepads need [`PERMISSION_GAME_CONTROL`](/constants/PERMISSION_GAME_CONTROL/) and viewer support.

## Concepts

- Clicking an object raises [touch events](/features/input/touch/), with [who touched](/functions/llDetectedKey/), [which prim](/functions/llDetectedLinkNumber/) and [where](/functions/llDetectedTouchST/) read by the detected functions
  - A [click action](/functions/llSetClickAction/) changes what a left-click does
- Scripts can [capture](/functions/llTakeControls/) movement keys and the left mouse button
  - Needs [permission](/functions/llRequestPermissions/) from the avatar, granted in [`run_time_permissions`](/events/run_time_permissions/)
  - The [`control`](/events/control/) event reports which keys are held and which changed
  - Controls can also pass through to normal movement
  - Sitting avatars can be [forced into mouselook](/functions/llForceMouselook/), and [agent info](/functions/llGetAgentInfo/) tells whether an avatar is [in mouselook](/constants/AGENT_MOUSELOOK/)
- [Gamepad](/features/input/gamepad/) buttons and axes arrive in [`game_control`](/events/game_control/), for scripts in attachments or seats

## Functions and events

- `event` [`touch_start`](/events/touch_start/) `(integer num_detected)`
- `event` [`touch`](/events/touch/) `(integer num_detected)`
- `event` [`touch_end`](/events/touch_end/) `(integer num_detected)`
- `integer` [`llDetectedTouchFace`](/functions/llDetectedTouchFace/) `(integer index)`
- `void` [`llSetClickAction`](/functions/llSetClickAction/) `(integer action)`
- `void` [`llTakeControls`](/functions/llTakeControls/) `(integer controls, integer accept, integer pass_on)`
- `void` [`llReleaseControls`](/functions/llReleaseControls/) `()`
- `event` [`control`](/events/control/) `(key id, integer level, integer edge)`
- `event` [`game_control`](/events/game_control/) `(key id, integer button_levels, list axes)`

## [Touch](/features/input/touch/)

[Touch events](/events/touch_start/), [where a prim was touched](/functions/llDetectedTouchFace/), click actions and touch text.

## [Gamepad](/features/input/gamepad/)

Game controller [buttons and axes](/events/game_control/) and the avatar's [game-control mode](/functions/llGetGameControlMode/), with modal axes and buttons per mode.

## Scripting Details

- `void` [`llRequestPermissions`](/functions/llRequestPermissions/) `(key agent, integer permissions)`: Requests permissions (a bitfield specified by permissions) from the agent in the same region, calling run_time_permissions if granted. This call does not pause script execution.
- `event` [`run_time_permissions`](/events/run_time_permissions/) `(integer perm)`: Triggered when an agent grants or denies runtime permissions requested by llRequestPermissions. Passes the active integer permissions bitfield perm (returns 0 if no permissions are currently granted).
- `void` [`llTakeControls`](/functions/llTakeControls/) `(integer controls, integer accept, integer pass_on)`: Intercepts inputs (keyboard/mouse clicks) from the agent, specifically those specified by controls. The boolean accept determines if events are generated, and pass_on determines if inputs also perform their default functions. Requires the PERMISSION_TAKE_CONTROLS runtime permission.
- `void` [`llReleaseControls`](/functions/llReleaseControls/) `()`: Stops taking inputs (previously acquired via llTakeControls) from the avatar, dequeuing any remaining control events and revoking the PERMISSION_TAKE_CONTROLS permission.
- `event` [`control`](/events/control/) `(key id, integer level, integer edge)`: Triggered to pass captured avatar control inputs into the script. The parameter level indicates held controls, and edge indicates change in controls (both are bitfields of CONTROL_* constants).
- `void` [`llForceMouselook`](/functions/llForceMouselook/) `(integer mouselook)`: Sets whether any avatar sitting on this prim is forced into mouselook mode. Setting mouselook to TRUE forces the mode; FALSE (default) allows the avatar to keep their current camera mode.
- `integer` [`llGetAgentInfo`](/functions/llGetAgentInfo/) `(key id)`: Returns an integer bitfield containing status information about the agent specified by id (such as AGENT_FLYING, AGENT_ATTACHMENTS, AGENT_SITTING, etc.).

## Additional

- [`llRequestPermissions`](/functions/llRequestPermissions/) — permissions for input
  - [`PERMISSION_TAKE_CONTROLS`](/constants/PERMISSION_TAKE_CONTROLS/) — allows [`llTakeControls`](/functions/llTakeControls/)
  - [`PERMISSION_GAME_CONTROL`](/constants/PERMISSION_GAME_CONTROL/) — needed for gamepad input
- [`llTakeControls`](/functions/llTakeControls/) — keys to capture are `CONTROL_*` [control buttons](/constants/groups/ControlButton/)

## Keyboard and mouse controls

Constant groups: [ControlButton](/constants/groups/ControlButton/) (10)

See also: [Input](/categories/input/), [LSL Controls (Second Life Wiki)](https://wiki.secondlife.com/wiki/Category:LSL_Controls)
   (planned: Guide: capturing controls for a vehicle or weapon)

## Related

See also: [Dialog](/features/dialog/), [Communications](/features/communications/), [Camera](/features/camera/)

## Related features

- [Dialog](/features/dialog/)
- [Camera](/features/camera/)
- [Avatars](/features/avatar/)

## Categories

- [Touch](/categories/touch/)
- [Input](/categories/input/)
- [Gamepad](/categories/gamepad/)

---

From lsl.dev: https://lsl.dev/features/input/
