Skip to content

Toggle action

Goal: pressing F8 toggles an information block.

{
"Actions": [
{
"Name": "TogglePanel",
"Type": "Button",
"Binding": {
"Path": "<Keyboard>/f8"
}
}
]
}

The game rebuilds the module action map after the file is saved.

local PanelVisible = true
local ToggleAction = InputActions:FindAction("TogglePanel")
if ToggleAction == nil then
print("TogglePanel action was not found")
else
ToggleAction:OnPerformed(function()
PanelVisible = not PanelVisible
end)
end
Scheduler:OnFrame(function()
if not PanelVisible then
return
end
ImGui:DrawText(
"Panel enabled",
Rect.new(24, 140, 240, 40),
18,
Color.new(0.5, 1, 0.7, 1),
TextAnchor.MiddleLeft
)
end)

In the current build, InputAction:Disable() does not reliably suppress a previously registered OnPerformed(). Control behavior through PanelVisible or a separate InputEnabled flag.

Read IsPressed() every frame when an action should remain active while held:

Scheduler:OnFrame(function()
if ToggleAction ~= nil and ToggleAction:IsPressed() then
ImGui:DrawDebugText("F8 is held")
end
end)

Reference: InputAction, Scheduler, and ImGui.