Controls
A script can capture an avatar’s movement keys and left mouse button, which is how vehicles, weapons and HUDs read input. Part of the Input feature.
Concepts
- Controls need
PERMISSION_TAKE_CONTROLS, requested from the avatar and granted inrun_time_permissions- Granted without a dialog when the avatar is sitting on the object or wearing it
llTakeControlstakes controls, a mask ofCONTROL_*control buttonsllReleaseControlsgives the controls back and also revokesPERMISSION_TAKE_CONTROLS- A script that has taken controls keeps running in “No Outside Scripts” parcels, which keeps vehicles and AOs working; this applies only to the prim holding the script
controlpasses id, the avatar, plus two masks ofCONTROL_*bits- level has a bit set for each control held down
- edge has a bit set for each control that changed since the last event
- Mouselook
CONTROL_LBUTTONis the left mouse button in normal view,CONTROL_ML_LBUTTONthe same button in mouselookllForceMouselookputs avatars that sit on the prim into mouselookllGetAgentInforeportsAGENT_MOUSELOOKwhile an avatar is in mouselook
Functions and events
llRequestPermissions(key agent, integer permissions) | |
event | run_time_permissions(integer perm) |
llTakeControls(integer controls, integer accept, integer pass_on) | |
llReleaseControls() | |
event | control(key id, integer level, integer edge) |
llForceMouselook(integer mouselook) |
Presses, releases and held keys
Combine level and edge in the control event:
integer start = level & edge; // pressed this eventinteger end = ~level & edge; // released this eventinteger held = level & ~edge; // still heldTouch
Clicking objects, touch positions, click actions and touch text.
Game Control
Controller-shaped buttons and axes, from a game controller or translated keyboard and mouse, and game-control modes.
Scripting Details
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(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). |
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. | |
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(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). |
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(key id)Returns an integer bitfield containing status information about the agent specified by id (such as AGENT_FLYING, AGENT_ATTACHMENTS, AGENT_SITTING, etc.). |
Constant groups
Section titled “Constant groups”Constant groups ControlButton 10
Related
Section titled “Related”See also Feature InputFeature PermissionsCategory InputSL Wiki LSL ControlsPlanned Guide: capturing controls for a vehicle or weapon