Skip to main content

Debug Keys

Version History

Build VersionChange DateChange TypeDescription
6760422025-06-21stableCurrent stable implementation

Overview

The debugkeys module provides a comprehensive debug key binding system for Don't Starve Together, enabling developers to access game manipulation tools, testing functionality, and debug panels through keyboard and mouse shortcuts. This system includes global key bindings, programmer-specific shortcuts, debug window controls, and mouse handling for debug operations.

Development Only

Debug keys are intended for development and testing purposes only. They are automatically disabled on Steam Deck and require appropriate debug flags to be enabled.

Usage Example

-- Register a global debug key
AddGlobalDebugKey(KEY_F1, function()
print("Global debug key pressed")
return true
end)

-- Register a game-specific debug key
AddGameDebugKey(KEY_G, function()
if TheInput:IsKeyDown(KEY_CTRL) then
c_godmode()
return true
end
end)

-- Handle debug key events
DoDebugKey(KEY_G, true) -- Process key down event

Functions

DoDebugKey(key, down)

Status: stable

Description: Processes debug key events by calling registered handlers for the specified key.

Parameters:

  • key (number): The key code being processed
  • down (boolean): Whether the key is being pressed (true) or released (false)

Returns:

  • (boolean): true if any handler consumed the key event, false otherwise

Example:

-- Process a key down event
local consumed = DoDebugKey(KEY_G, true)
if consumed then
print("Key was handled by debug system")
end

Version History:

  • Current implementation since build 676042

AddGameDebugKey(key, fn, down)

Status: stable

Description: Registers a debug key handler that only functions when in active gameplay.

Parameters:

  • key (number): The key code to bind
  • fn (function): Handler function to call when key is pressed
  • down (boolean, optional): Whether to trigger on key down (true) or up (false). Default: true

Example:

-- Add a debug key that only works in-game
AddGameDebugKey(KEY_F2, function()
if c_sel() == TheWorld then
c_select(TheWorld.net)
else
c_select(TheWorld)
end
return true
end)

Version History:

  • Current implementation since build 676042

AddGlobalDebugKey(key, fn, down)

Status: stable

Description: Registers a debug key handler that functions globally, regardless of game state.

Parameters:

  • key (number): The key code to bind
  • fn (function): Handler function to call when key is pressed
  • down (boolean, optional): Whether to trigger on key down (true) or up (false). Default: true

Example:

-- Add a global debug key
AddGlobalDebugKey(KEY_HOME, function()
if not TheSim:IsDebugPaused() then
TheSim:ToggleDebugPause()
else
TheSim:Step()
end
return true
end)

Version History:

  • Current implementation since build 676042

SimBreakPoint()

Status: stable

Description: Sets a simulation breakpoint by pausing the game if not already paused.

Example:

-- Set a breakpoint in code
SimBreakPoint()
-- Game will pause at this point for debugging

Version History:

  • Current implementation since build 676042

DoReload()

Status: stable

Description: Performs a hot reload of the game scripts by clearing the reload module cache and re-requiring it.

Example:

-- Trigger a hot reload
DoReload()
-- Scripts will be reloaded without restarting the game

Version History:

  • Current implementation since build 676042

DoDebugMouse(button, down, x, y)

Status: stable

Description: Handles debug mouse events for entity manipulation and debugging.

Parameters:

  • button (number): Mouse button pressed (MOUSEBUTTON_LEFT, MOUSEBUTTON_RIGHT)
  • down (boolean): Whether button is pressed down
  • x, y (numbers): Screen coordinates of mouse click

Mouse Actions:

  • Right Click + Ctrl + Shift: Spawn selected prefab at cursor
  • Right Click + Ctrl: Remove entity under mouse or kill nearby entities
  • Right Click + Alt: Print distance and angle information
  • Right Click + Shift: Set entity under mouse as debug target
  • Left Click (when paused): Set entity under mouse as debug target

Example:

-- Handle mouse events in debug context
DoDebugMouse(MOUSEBUTTON_RIGHT, true, mouseX, mouseY)

Version History:

  • Current implementation since build 676042

DebugKeyPlayer()

Status: stable

Description: Gets the player entity for debug operations, only returning a player on master simulation.

Returns:

  • (Entity|nil): Player entity if on master sim, nil otherwise

Example:

local player = DebugKeyPlayer()
if player then
player.components.health:DoDelta(25)
end

Version History:

  • Current implementation since build 676042

d_addemotekeys()

Status: stable

Description: Registers numpad keys for quick emote access during debugging.

Emote Key Bindings:

  • Numpad 0: Sit emote
  • Numpad 1: Happy emote
  • Numpad 2: Joy emote
  • Numpad 3: Slow clap emote
  • Numpad 4: No emote
  • Numpad 5: Angry emote
  • Numpad 6: Face palm emote
  • Numpad 7: Impatient emote
  • Numpad 8: Shrug emote
  • Numpad 9: Wave emote
  • Numpad Period: Fist shake emote

Example:

-- Enable emote debug keys
d_addemotekeys()
-- Now numpad keys will trigger emotes

Version History:

  • Current implementation since build 676042

d_gettiles()

Status: stable

Description: Scans a 11x11 area around the player for farming soil tiles and dumps their coordinates.

Example:

-- Find farming soil tiles around player
d_gettiles()
-- Outputs table of tile coordinates to console

Version History:

  • Current implementation since build 676042

Key Binding Categories

Global Key Bindings

These key bindings work regardless of game state:

Key CombinationFunctionDescription
HomePause/Step GamePauses game or steps one frame if paused
Ctrl + HomeToggle PauseToggles pause state
GGod ModeEnables/disables god mode
Shift + GSuper God ModeGod mode + restore health/hunger/sanity
Ctrl + AUnlock RecipesEnables free crafting
F1Select EntitySelects entity under mouse cursor
Ctrl + WToggle IMGUIOpens/closes debug interface
Shift + F10Next Nightmare PhaseAdvances nightmare cycle
F10Next Day PhaseAdvances day/night cycle

Programmer Key Bindings

Advanced debugging tools for developers:

Key CombinationFunctionDescription
Alt + F1Select WorldSelects world entity for debugging
Ctrl + F1Toggle Perf GraphShows/hides performance graphs

Window Key Bindings

Debug panel shortcuts (requires CAN_USE_DBUI):

Key CombinationPanelDescription
Shift + PPrefabs PanelOpens prefab debugging interface
Shift + AAudio PanelOpens audio debugging tools
Shift + EEntity PanelOpens entity inspection panel
Shift + CConsole PanelOpens debug console
Shift + FWatch PanelOpens variable watch panel
Shift + Alt + SSkins PanelOpens skin debugging tools

Game Debug Keys

In-game manipulation shortcuts:

Key CombinationFunctionDescription
F2Toggle World SelectionSwitches between world and world.net
F3Advance SeasonSkips to next season
F4Spawn BaseCreates a complete base setup
F5Weather ControlLightning/meteor spawning
F7Topology InfoShows world topology information
F8Spawn Items in RingsCreates item rings around player
F9Fast ForwardAdvances time by 6 hours
TTeleportTeleports to cursor or map position
MMap DebugToggles fog of war and reveals areas
Ctrl + SSave GameForces game save

Entity Manipulation Keys

Key CombinationFunctionDescription
XSelect EntitySelects entity under mouse
Ctrl + XSelect Equipped ItemSelects item in player's hands
Ctrl + KRemove EntityRemoves entity under mouse
Ctrl + GGrow/ManipulateGrows plants or manipulates entity

Player Status Keys

Key CombinationFunctionDescription
Numpad +Restore StatsIncreases health/hunger/sanity
Numpad -Drain StatsDecreases health/hunger/sanity
Ctrl + Numpad +Full RestoreRestores all stats to maximum
[ ]Time ScaleAdjusts game speed

Key Binding System

Handler Registration

The system uses a table-based approach to store multiple handlers per key:

handlers = {}

-- Internal handler storage structure
handlers[KEY_G] = {
function(down)
if down and inGamePlay then
return godmode_handler()
end
end,
function(down)
if down then
return other_handler()
end
end
}

Modifier Key Support

The system supports complex key combinations with modifiers:

local binding = {
key = KEY_F1,
CTRL = true, -- Requires Ctrl to be held
SHIFT = false, -- Requires Shift to NOT be held
ALT = nil -- Ignores Alt key state
}

Platform Restrictions

-- Automatically disabled on Steam Deck
if IsSteamDeck() then
return
end

Debug Mouse Functions

Right Click Actions

  • Ctrl + Shift + Right Click: Spawn selected prefab at cursor location
  • Ctrl + Right Click: Remove entity under mouse or kill nearby entities
  • Alt + Right Click: Display distance and angle information
  • Shift + Right Click: Set entity as debug target

Left Click Actions

  • Left Click (when game paused): Set entity under mouse as debug target

Dependencies

Required Systems

  • Input System: Keyboard and mouse input handling
  • Debug UI System: Debug panel management (when CAN_USE_DBUI is enabled)
  • Console System: Command execution and entity selection
  • Entity Framework: Entity manipulation and inspection

Global Functions Used

  • TheInput: Input state checking and world position
  • TheSim: Simulation control and debug features
  • TheFrontEnd: Debug panel management
  • ConsoleCommandPlayer(): Player entity access
  • ConsoleRemote(): Remote command execution

Required Modules

  • consolecommands: Console command functionality
  • usercommands: User command system for emotes
  • Various dbui_no_package/* modules for debug panels

Configuration Variables

Debug Flags

global("CHEATS_ENABLED")         -- Enables cheat functionality
global("CHEATS_KEEP_SAVE") -- Preserves saves when cheating
global("CHEATS_ENABLE_DPRINT") -- Enables debug printing
global("CAN_USE_DBUI") -- Enables debug UI panels

User-Specific Settings

local userName = TheSim:GetUsersName()
-- Custom debug settings based on username
if CHEATS_ENABLED and userName == "My Username" then
DPRINT_USERNAME = "My Username"
CHEATS_KEEP_SAVE = true
CHEATS_ENABLE_DPRINT = true
end

Usage Guidelines

Development Best Practices

  1. Key Registration: Register debug keys early in the loading process
  2. Return Values: Always return true from handlers that consume the key event
  3. Modifier Checks: Use modifier key checks for complex combinations
  4. Safety Checks: Verify entity validity before manipulation

Common Patterns

-- Standard debug key pattern
AddGameDebugKey(KEY_EXAMPLE, function()
if TheInput:IsKeyDown(KEY_CTRL) then
-- Control variant
return do_control_action()
elseif TheInput:IsKeyDown(KEY_SHIFT) then
-- Shift variant
return do_shift_action()
else
-- Default action
return do_default_action()
end
end)

Security Considerations

  • Master Simulation: Many functions only work on master simulation
  • Entity Validation: Always check entity validity before manipulation
  • Error Handling: Include safety checks for debug operations
  • Platform Restrictions: Automatic disable on restricted platforms

Notes

  • Platform Support: Automatically disabled on Steam Deck
  • Debug UI: Many features require CAN_USE_DBUI flag
  • Performance Impact: Debug operations can affect game performance
  • Development Tool: Intended for development and testing only
  • Key Conflicts: Be aware of potential conflicts with game controls
  • Hot Reload: Supports hot reloading of scripts for development
  • Network Sync: Some operations automatically sync between client and server