Keys, mouse and rebinding
Distinguish physical keys from symbols, preserve gamepad bindings and capture the mouse correctly.
Actions instead of keys
Define Input Map actions for movement and game commands so keyboard and gamepad use the same code. For text entry, use LineEdit or TextEdit rather than a list of gameplay actions.
| InputEventKey field | Use |
|---|---|
PhysicalKeycode | Physical key position, such as the usual WASD arrangement regardless of keyboard layout |
Keycode | Latin key label in the current layout, such as S for Ctrl + S |
KeyLabel | Localized key label for player prompts |
Unicode | Entered character; this alone is not a full text field with IME support |
Rebind only the keyboard
This class does not attach to an entity. Save it as KeyboardBindings.cs. KeyboardBindings.SetPhysicalKey("interact", Key.F) replaces keyboard bindings for an existing action while preserving mouse and gamepad bindings:
using Reckfell;
public static class KeyboardBindings
{
public static Error SetPhysicalKey(string action, Key key)
{
if (!InputMap.HasAction(action))
return Error.DoesNotExist;
foreach (InputEvent binding in InputMap.ActionGetEvents(action))
{
if (binding is InputEventKey)
InputMap.ActionEraseEvent(action, binding);
}
InputMap.ActionAddEvent(action, new InputEventKey { PhysicalKeycode = key });
return Error.Ok;
}
}Check the result: an unknown action returns Error.DoesNotExist. Rebind after finishing event capture so the new key does not trigger a game command from that same event. Disable gameplay controls while the binding screen is open; provide cancellation and restore defaults.
Runtime Input Map changes are not automatically saved to project.reckfell. Write chosen bindings to user:// and restore them at startup. Store the action name, event kind, key code and modifiers if your UI supports them. See saving data.
Camera and mouse
For first-person look, set Input.MouseMode = Input.MouseModeEnum.Captured. Read InputEventMouseMotion.ScreenRelative for screen-space motion; Relative depends on window content scaling. This is already an event displacement, so do not multiply it by delta as if it were a speed.
When opening a menu, return to Input.MouseModeEnum.Visible and disable camera rotation. Capture again deliberately when closing it. Test loss of window focus and exiting capture separately.
Gamepad
Bind positive and negative stick directions to actions and read them with GetVector(). Tune the dead zone on a real device: too small causes drift; too large reduces precision. Handle controller disconnection and avoid assuming a single permanent device index.