Input Bindings - Kyoril/mmo GitHub Wiki
This page should describe what input bindings are and how you can use and extend them.
Like every game, our game needs to handle player input. Input bindings are a way to define actions which can be triggered by doing actual input like pressing a button on your keyboard or on your mouse.
Input bindings are only used in the actual game, not in the login screen, realm selection screen or character selection screen.
Your data folder has a Interface/bindings.xml file. This file contains a <Bindings>
root tag and in that tag there are multiple <Binding>
tags like so:
<Binding name="MOVEFORWARD" description="Move forward" category="MOVEMENT">
return function(key, keystate)
-- Lua code
end
</Binding>
As you might have noticed, the file is in the Interface folder. This means that the lua code in the <Binding>
tag is actually user interface lua. You can use everything in there which you can also use in the GameUI
section of the user interface.
As you see, each Binding has a few properties as well:
- name The name of the input binding in uppercase characters without any spaces. This name will be displayed in the user interface as localized string some day.
- description A description of what this input action will do when triggered.
- category A localized category string which is used to group multiple bindings together in the user interface in order for players to find related input bindings more quickly.
The lua code is expected to return a function with two arguments:
- key A string which contains the name of the key. This will be "ESCAPE" for the escape key, "D" for the D key etc. Most of the time you won't really need this.
- keystate A string which will either be "UP" or "DOWN" and indicates whether this binding was triggered by pressing or releasing the button. Keep in mind that the binding is repeatedly triggered while holding the button down, but only once per button release.
Now there is one last step missing: We have defined input bindings, named them and added code which tells the game what to do when the binding is executed. But how is such a binding actually executed?
Thats where the Config/DefaultBindings.cfg file comes in place. This is a console command file where each line is an actual console command.
As you can see in the sample file linked, it binds keys to input bindings by name like this:
bind W MOVEFORWARD
So the "W" key is bound to the "MOVEFORWARD" input binding, so when we hit or release W, the lua code of MOVEFORWARD is actually executed!
You can also see that you can bind any number of buttons to the same input binding, because you see that not only the "W" key is bound to MOVEFORWARD, but also the "UP" key (which is the up arrow button). You can use both these buttons to move your character forward.
However, you can only bind one input binding per key. If you were now to bind another binding to the W key again, the old MOVEFORWARD binding would be replaced with your new binding.
As these are console commands, you can dynamically bind keys to commands in the game from the console as well!
Whats missing is a separate Bindings.cfg while in the game which allows the user to save his customized keybinds for the game and which is then loaded whenever the game launches. This is something that needs to be done and should even be synchronized with the login servers as you might want to use that same input binding config on multiple machines when playing on the same account.
After reading this page, you should now be able to understand what input bindings are, where they are located and how actual input buttons are bound to input actions. You should also be able to create new input bindings yourself and bind them.