You can use SMAPI's [[Modding:Modder Guide/APIs/Input#SButton|<tt>SButton</tt>]] type directly in your config model to configure keybindings:
+
You can use SMAPI's [[Modding:Modder Guide/APIs/Input#KeybindList|<tt>KeybindList</tt>]] in your model to let users configure keybinds. This automatically supports multi-key or alternative bindings (e.g. to support split-screen mode):
+
<syntaxhighlight lang="c#">
<syntaxhighlight lang="c#">
class ModConfig
class ModConfig
{
{
−
public SButton ToggleKey { get; set; } = SButton.F2;
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:
−
−
<syntaxhighlight lang="c#">
−
class ModConfig
−
{
−
public KeybindList ToggleKey { get; set; } = KeybindList.ForSingle(SButton.F2);
−
}
−
</syntaxhighlight>
−
−
This is written/parsed the same way, but lets players specify multi-key or alternative bindings like <code>"LeftShift + F2, LeftTrigger"</code>.