View Page Source

Revision (current)
Last Updated by feos on 8/4/2022 1:55 PM
Back to Page


This page explains how to control input to the program using Lua. You can simulate autohold and autofire, and create macros this way.

! A simple autohold script

Suppose you want to hold down the Y button in snes9x. Just run this script:

%%SRC_EMBED lua
while true do
  joypad.set(1, {Y=1})
  emu.frameadvance()
end
%%END_EMBED

You can also use "Y=true" in place of "Y=1". The notation "{Y=1}" indicates a table with key Y set to 1. If variable c is a table, then c.Y (or c["Y"]) is the key Y associated with the table c. So you can write it this way:

%%SRC_EMBED lua
local c={}
c.Y=1
while true do
  joypad.set(1, c)
  emu.frameadvance()
end
%%END_EMBED

If you wanted to have player 2 hold left, you would do it as follows:

%%SRC_EMBED lua
local c={}
while true do
  joypad.set(2, {left=1})
  emu.frameadvance()
end
%%END_EMBED

See [LuaScripting/TableKeys|a list of table keys] for what the keys are named. They are different for each emulator.

[TODO]