In this tutorial I will explain how to remap input keys using an XML file and a configuration dialog box. First of all, here’s the config dialog. I assume you are familiar with the TGB GUI builder for this.

Most of the action will take place in the listbox under “Keyboard input”, wich is a GuiTextListCtrl object. When the dialog box is opened, the input configuration is read from the config file and put in the list. This is the config section for the keyboard input:
<?xml version=”1.0″ encoding=”utf-8″ standalone=”yes” ?>
<KeyboardSettings>
<Leftkey>left</Leftkey>
<Rightkey>right</Rightkey>
<Upkey>up</Upkey>
<Downkey>down</Downkey>
<Subfire>lcontrol</Subfire>
<Shipfire>lalt</Shipfire>
</KeyboardSettings>
And this piece of TorqueScript will read the settings and put them in the dialog box:
function FillKeylist()
{
//Open config file
%Xml = new ScriptObject()
{
class = “XML”;
};
%Xml.beginRead($ConfigFile);
%Xml.readClassBegin(”KeyboardSettings”);
//Clear and fill list
KeyboardList.clear();
KeyboardList.addRow(0,”Left” TAB %Xml.readField(”Leftkey”),0);
KeyboardList.addRow(1,”Right” TAB %Xml.readField(”Rightkey”),1);
KeyboardList.addRow(2,”Up” TAB %Xml.readField(”Upkey”),2);
KeyboardList.addRow(3,”Down” TAB %Xml.readField(”Downkey”),3);
KeyboardList.addRow(4,”Anti-sub torpedo” TAB %Xml.readField(”Subfire”),4);
KeyboardList.addRow(5,”Anti-ship torpedo” TAB %Xml.readField(”Shipfire”),5);
%Xml.readClassEnd();
%Xml.delete();
}
So now we have a list of input keys, now we need a way to change these. For this, a new dialog box “RemapDialog” is created, wich is opened when the list is double clicked (put canvas.pushDialog(…) in the AltCommand field). The RemapDialog window is a small window wich holds a text label and, most important of all, a GuiInputCtrl object. This is as good as undocumented, so it took me a while to figure out how to use it. The key function here is the “onInputEvent” callback. This is executed whenever an input event takes place. Here’s the code for retrieving the key wich was pressed:
function RemapInput::onInputEvent(%this, %device, %action)
{
//Only respond to keyboard input
if (%device $= “keyboard”)
{
//Close dialog
canvas.popDialog(RemapDialog);
//Remap the keys
RemapInputkeys(%action);
}
}
The %device parameter is used to filter out keyboard input, so the event ignores mouse events. The %action parameter is the key that was pressed. This is a string value wich you can use for the “bindCmd” function. I won’t go into detail about the RemapInputKeys function. What this does is replacing the entry in the input key list and saving it to the configuration file, but those are topics that are well documented (check my previous tutorial for info on reading and writing XML files).
Perhaps I’ll write a small demo project that demonstrates this all, and make it available with the source code so you can experiment with it.

