Key / mouse shortcuts

We have some global key/mouse shortcuts:

  • Input_Interact in CastleViewport unit.
  • PlayerInput_* in CastlePlayer unit. These are useful if you make a typical 3D game with the help of TPlayer class. In this case, PlayerInput_* override some navigation shortcuts, and allow to use player's inventory.
Global shortcuts are gathered inside InputsAll global map. Thanks to this global map, you can let user to configure game controls, you can detect key conflicts and handle them however you like, etc.

There are also local inputs, local to a specific navigation instance, inside Input_Xxx properties of TCastleWalkNavigation and TCastleExamineNavigation. If you use TPlayer then TPlayer uses it's own TCastleWalkNavigation, and overrides (most of) navigation inputs with global PlayerInput_Xxx, so (most of) the TCastleWalkNavigation.Input_Xxx controls should not be accessed directly, instead change only the global PlayerInput_Xxx. TPlayer sets typical AWSD key controls scheme, and they are also state-sensitive: they change appropriately when player is dead or blocked (see TPlayer.Dead and TPlayer.Blocked).

Every key/mouse shortcut is a TInputShortcut. They are configurable, you can change the shortcuts whenever you want (see TInputShortcut.Assign and other methods). You can also detect conflicts in the keymap and handle them however you like (see GameControlsMenu unit in "The Castle 1" sources for example).

The state of keys on the global keymap (CastleInputs.InputsAll) can be saved/loaded to the config file, if you call InputsAll.SaveToConfig(UserConfig) and InputsAll.LoadFromConfig(UserConfig). See the chapter User preferences for more information about this.

You can also create new TInputShortcut descendants. Then can be global (added to InputsAll, saved to config file and such) or local. See CastleInputs unit API docs. You can easily handle them by overriding TCastleUserInterface.Press or TCastleControlBase.EventPress or TCastleWindowBase.EventPress methods, or assigning TCastleControlBase.OnPress or TCastleWindowBase.OnPress callbacks. You will find then useful methods TInputShortcut.IsEvent(TInputPressRelease) (to detect press/release of input) and TInputShortcut.IsPressed(IUIContainer) (to detect holding (keeping pressed) of input).

An example application that creates a set of custom TInputShortcut instances, and saves/loads them to config file, is in examples/3d_rendering_processing/custom_input_shortcuts_saved_to_config.lpr.