Changes

Jump to navigation Jump to search
+ keybind settings
Line 81: Line 81:     
That's it! When the player launches the game, SMAPI will create the <tt>config.json</tt> file automatically if it doesn't exist yet, using the default config options you provided in your model. If you need to save some changes, you can use <tt>this.Helper.WriteConfig(this.Config)</tt>.
 
That's it! When the player launches the game, SMAPI will create the <tt>config.json</tt> file automatically if it doesn't exist yet, using the default config options you provided in your model. If you need to save some changes, you can use <tt>this.Helper.WriteConfig(this.Config)</tt>.
 +
 +
==Keybind settings==
 +
: {{main article|Modding:Modder Guide/APIs/Input}}
 +
 +
You can use SMAPI's [[Modding:Modder Guide/APIs/Input#SButton|<tt>SButton</tt>]] type directly in your config model to configure keybindings:
 +
<source lang="c#">
 +
class ModConfig
 +
{
 +
  public SButton ToggleKey { get; set; } = SButton.F2;
 +
}
 +
</source>
 +
 +
The value is automatically written/parsed in the <tt>config.json</tt> file as a string:
 +
<source lang="json">
 +
{
 +
  "ToggleKey": "F2"
 +
}
 +
</source>
 +
 +
{{SMAPI upcoming|3.9|
 +
For compatibility with split-screen (when you may have players on both keyboard and controller), you should use [[Modding:Modder Guide/APIs/Input#KeybindList|<tt>KeybindList</tt>]] instead:
 +
 +
<source lang="c#">
 +
class ModConfig
 +
{
 +
  public KeybindList ToggleKey { get; set; } = KeybindList.ForSingle(SButton.F2);
 +
}
 +
</source>
 +
 +
This is written/parsed the same way, but lets players specify multi-key or alternative bindings like <code>"LeftShift + F2, LeftTrigger"</code>.
 +
}}
translators
8,403

edits

Navigation menu