Skip to content
lsl.devlsl.devLSL Dev

control

event
Event syntax
control(
  1. key id,// UUID of the avatar whose inputs are captured.
  2. integer level,// A bitfield of CONTROL_* constants representing currently held controls. Values: ControlButton
  3. integer edge// A bitfield of CONTROL_* constants representing controls that just changed state. Values: ControlButton
) { … }

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).

Result of llTakeControls library function call and user input.

How to use
control(key id, integer level, integer edge)
{
}
ConstantValueDescription
CONTROL_FWD0x00000001Move forward control (↑ or W)
CONTROL_BACK0x00000002Move back control (↓ or S)
CONTROL_LEFT0x00000004Move left control (← or A [← or A in mouselook])
CONTROL_RIGHT0x00000008Move right control (→ or D [→ or D in mouselook])
CONTROL_ROT_LEFT0x00000100Rotate left control (← or A)
CONTROL_ROT_RIGHT0x00000200Rotate right control (→ or D)
CONTROL_UP0x00000010Move up control (PgUp or E)
CONTROL_DOWN0x00000020Move down control (PgDn or C)
CONTROL_LBUTTON0x10000000Left mouse button control
CONTROL_ML_LBUTTON0x40000000Left mouse button control while in mouselook
(undocumented)0x02000000Avatar left rotation detected. Triggers llGetAnimation == “Turning Left”
(undocumented)0x04000000Avatar right rotation detected. Triggers llGetAnimation == “Turning Right”
Example 1
24 collapsed lines
default
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
run_time_permissions(integer perm)
{
if(PERMISSION_TAKE_CONTROLS & perm)
{
llTakeControls(
CONTROL_FWD |
CONTROL_BACK |
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT |
CONTROL_UP |
CONTROL_DOWN |
CONTROL_LBUTTON |
CONTROL_ML_LBUTTON |
0, TRUE, FALSE);
// | 0 is for edit convenience,
// it does not change the mask.
}
}
control(key id, integer level, integer edge)
{
integer start = level & edge;
integer end = ~level & edge;
integer held = level & ~edge;
integer untouched = ~(level | edge);
llOwnerSay(llList2CSV([level, edge, start, end, held, untouched]));
}
}

llGetRot in mouselook for an attachment returns the angle the avatar is looking in.

There are some bugs when you put two scripts in the same prim and call LlTakeControls(), the id may not be the intended one. See SVC-3187.

From the issue templates included by the wiki article:

  • SCR-97 (bug): llTakeControls Traps repeating event when contols are changed or permission revoked
  • SVC-3187 (bug): llTakeControls overrides existing controls
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.