LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
controls

Buttons, analog sticks, touch screens & motion sensors. More...

Detailed Description

Call controls.update() once at the start of every frame, then check the buttons and sensors. The difference between the button functions:

local x = 480
while true do
controls.update()
if controls.check(SCE_CTRL_LEFT) then x = x - 4 end
if controls.check(SCE_CTRL_RIGHT) then x = x + 4 end
if controls.pressed(SCE_CTRL_START) then break end -- exit the loop
draw.circle(x, 272, 20, color.new(255, 255, 255))
draw.swapbuffers()
end
SceCtrlButtons SCE_CTRL_START
Start button.
Definition lj_controls.h:47
SceCtrlButtons SCE_CTRL_RIGHT
D-pad right.
Definition lj_controls.h:32
SceCtrlButtons SCE_CTRL_LEFT
D-pad left.
Definition lj_controls.h:31

You can check several buttons at once by adding them together, e.g. controls.check(SCE_CTRL_L1 + SCE_CTRL_R1).

Functions

nil controls.update (boolean ext, boolean bind)
 
boolean controls.pressed (SceCtrlButtons button)
 
boolean controls.held (SceCtrlButtons button)
 
boolean controls.released (SceCtrlButtons button)
 
boolean controls.check (SceCtrlButtons button)
 
number controls.leftanalog ()
 
number controls.rightanalog ()
 
table controls.accelerometer ()
 
table controls.gyroscope ()
 
table controls.fronttouch ()
 
table controls.reartouch ()
 
nil controls.vibrate (number small, number large, number port)
 
nil controls.lightbar (number r, number g, number b, number port)
 

Buttons

SceCtrlButtons SCE_CTRL_UP
 D-pad up.
 
SceCtrlButtons SCE_CTRL_DOWN
 D-pad down.
 
SceCtrlButtons SCE_CTRL_LEFT
 D-pad left.
 
SceCtrlButtons SCE_CTRL_RIGHT
 D-pad right.
 
SceCtrlButtons SCE_CTRL_CROSS
 Cross (✕) button.
 
SceCtrlButtons SCE_CTRL_CIRCLE
 Circle (○) button.
 
SceCtrlButtons SCE_CTRL_SQUARE
 Square (□) button.
 
SceCtrlButtons SCE_CTRL_TRIANGLE
 Triangle (△) button.
 
SceCtrlButtons SCE_CTRL_ACCEPT
 The "confirm" button set in the system settings (Cross or Circle, depending on the console's region/settings)
 
SceCtrlButtons SCE_CTRL_CANCEL
 The "back" button set in the system settings (Circle or Cross, the opposite of SCE_CTRL_ACCEPT)
 
SceCtrlButtons SCE_CTRL_LTRIGGER
 L button.
 
SceCtrlButtons SCE_CTRL_RTRIGGER
 R button.
 
SceCtrlButtons SCE_CTRL_L1
 L1 button (external controllers, or the L button when bind is used in controls.update())
 
SceCtrlButtons SCE_CTRL_R1
 R1 button (external controllers, or the R button when bind is used in controls.update())
 
SceCtrlButtons SCE_CTRL_L2
 L2 button (external controllers)
 
SceCtrlButtons SCE_CTRL_R2
 R2 button (external controllers)
 
SceCtrlButtons SCE_CTRL_L3
 L3 button, pressing the left stick (external controllers)
 
SceCtrlButtons SCE_CTRL_R3
 R3 button, pressing the right stick (external controllers)
 
SceCtrlButtons SCE_CTRL_START
 Start button.
 
SceCtrlButtons SCE_CTRL_SELECT
 Select button.
 
SceCtrlButtons SCE_CTRL_PSBUTTON
 PS button (only detected while it's locked with os.lock() and SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN)
 
SceCtrlButtons SCE_CTRL_POWER
 Power button.
 
SceCtrlButtons SCE_CTRL_VOLUP
 Volume up button.
 
SceCtrlButtons SCE_CTRL_VOLDOWN
 Volume down button.
 
SceCtrlButtons SCE_CTRL_HEADPHONE
 Headphones are plugged in.
 
SceCtrlButtons SCE_CTRL_INTERCEPTED
 The input is being used by the system (e.g. the quick menu is open)
 

Function Documentation

◆ controls.accelerometer()

table controls.accelerometer ( )

Gets the accelerometer (tilt) readings

Returns
A table with the fields x, y and z
Example:
local acc = controls.accelerometer()
draw.text(10, 10, "X: "..acc.x.." Y: "..acc.y.." Z: "..acc.z, white)

◆ controls.check()

boolean controls.check ( SceCtrlButtons button)

Checks if a button is down right now

Parameters
buttonOne of the button constants
Returns
true while the button is down

◆ controls.fronttouch()

table controls.fronttouch ( )

Gets the fingers touching the front touch screen

Returns
A list with one table per finger (empty if nothing is touching). Each table has these fields:
  • x, y: Position in screen pixels
  • force: How hard the finger is pressing
  • id: A number that stays the same for a finger while it keeps touching
Example:
local touch = controls.fronttouch()
for i = 1, #touch do
draw.circle(touch[i].x, touch[i].y, 30, color.new(255, 255, 255))
end

◆ controls.gyroscope()

table controls.gyroscope ( )

Gets the gyroscope (rotation speed) readings

Returns
A table with the fields x, y and z
Example:
local gyro = controls.gyroscope()
draw.text(10, 10, "X: "..gyro.x.." Y: "..gyro.y.." Z: "..gyro.z, white)

◆ controls.held()

boolean controls.held ( SceCtrlButtons button)

Checks if a button is being held down (it was already down on the previous controls.update())

Parameters
buttonOne of the button constants
Returns
true while the button is held, except on the frame it was first pressed

◆ controls.leftanalog()

number controls.leftanalog ( )

Gets the position of the left analog stick

Returns
2 numbers, X and Y, each from -128 to 127 (0 is the center, negative is left/up)
Example:
local lx, ly = controls.leftanalog()
if math.abs(lx) > 20 then player_x = player_x + lx / 32 end -- ignore small movements (dead zone)

◆ controls.lightbar()

nil controls.lightbar ( number r,
number g,
number b,
number port )

Sets the light bar color of a connected DualShock 4 controller

Parameters
rRed, 0-255
gGreen, 0-255
bBlue, 0-255
portController port (optional, default: 1)

◆ controls.pressed()

boolean controls.pressed ( SceCtrlButtons button)

Checks if a button was just pressed (it's down now, but wasn't on the previous controls.update())

Parameters
buttonOne of the button constants
Returns
true on the frame the button was pressed

◆ controls.reartouch()

table controls.reartouch ( )

Gets the fingers touching the rear touch pad. Works like controls.fronttouch().

Returns
A list with one table per finger (empty if nothing is touching), each with the fields x, y, force and id

◆ controls.released()

boolean controls.released ( SceCtrlButtons button)

Checks if a button was just released (it's up now, but was down on the previous controls.update())

Parameters
buttonOne of the button constants
Returns
true on the frame the button was released

◆ controls.rightanalog()

number controls.rightanalog ( )

Gets the position of the right analog stick

Returns
2 numbers, X and Y, each from -128 to 127 (0 is the center, negative is left/up)
Example:
local rx, ry = controls.rightanalog()

◆ controls.update()

nil controls.update ( boolean ext,
boolean bind )

Reads the latest state of the buttons, sticks, touch screens and motion sensors. Call this once per frame, before using any other function of this library.

Parameters
extUse the extended reading mode, which keeps reading input even while system dialogs (keyboard, messages, etc.) are open (optional, default: false)
bindMakes L and R also count as L1 and R1 (optional, default: false)

◆ controls.vibrate()

nil controls.vibrate ( number small,
number large,
number port )

Makes a connected DualShock controller vibrate (e.g. on a PS TV). Set both motors to 0 to stop.

Parameters
smallStrength of the small motor, 0-255
largeStrength of the large motor, 0-255
portController port (optional, default: 1)