Modding:Key Mapping (Commands)

Mods can add custom key mapping entries to the Key Mapping menu.



Players can then bind a key to the mod's custom command.

When the player presses that key, the mod's custom command is received as an event on the player character. This means that at least a small amount of C# scripting is required to take advantage of the key mapping infrastructure.

Define Key Mapping Options
A mod defines its custom key mapping options in a  file. Here's an example file that defines two commands.

In this case, we've added one command to the existing "Debug" category in the Key Mapping menu. We've added another command to a new category - the "Cool" category. Here's how it looks in game:



Creating a Part to Listen for the Command
Create a part to listen for your Key Mapping command on the player.

Adding the Part to the Player
Add your part to the player when a New Game is started. This section uses the method described in the Modding:Adding_Code_to_the_Player article. Refer to that article for more information, including how you can also add your part to the player when an existing save game is loaded.

Shipping Your Mod
Your completed mod should look like this. For more info about the proper Mods directory location, see File locations > Offline mods.