I always thought that there needed to be a default function to do this, but there isn't, so here you go:
function addKeyBind(%div,%name,%cmd,%device,%action,%overWrite)
{
if(%device !$= "" && %action !$= "")
{
if(moveMap.getCommand(%device,%action) $= "" || %overWrite)
moveMap.bind(%device,%action,%cmd);
}
%divIndex = -1;
for(%i=0; %i < $RemapCount; %i++)
{
if($RemapDivision[%i] $= %div)
{
%divIndex = %i;
break;
}
}
if(%divIndex >= 0)
{
for(%i=$RemapCount-1; %i > %divIndex; %i--)
{
$RemapDivision[%i+1] = $RemapDivision[%i];
$RemapName[%i+1] = $RemapName[%i];
$RemapCmd[%i+1] = $RemapCmd[%i];
}
$RemapDivision[%divIndex+1] = "";
$RemapName[%divIndex+1] = %name;
$RemapCmd[%divIndex+1] = %cmd;
$RemapCount ++;
}
else
{
$RemapDivision[$RemapCount] = %div;
$RemapName[$RemapCount] = %name;
$RemapCmd[$RemapCount] = %cmd;
$RemapCount ++;
}
}
This adds a keybind, and if desired can forcibly or non-forcibly bind it to a key.
addKeyBind("Division","Name","command","keyboard","alt f",0);
Division - If the division used already exists, the bind will be added under the existing division.
Name - The name of the bind.
Command - The command called when this bind is used. The function called has one variable for the state of the bound key (bool up/down).
Device - This is not needed for normal use! This is used when setting the bind to a key. (keyboard/mouse)
Action - This is not needed for normal use! This is used when setting the bind to a key. Set this to an action such as "shift G" or "alt v".
Overwrite - This is not needed for normal use! This is used when setting the bind to a key. If this is true, any existing binding using the specified device/action will be overwritten. (bool)
function removeKeyBind(%div,%name,%cmd)
{
%binding = moveMap.getBinding(%cmd);
%device = getField(%binding,0);
%action = getField(%binding,1);
if(%device !$= "" && %action !$= "")
moveMap.unBind(%device,%action);
for(%i=0; %i < $RemapCount; %i++)
{
%d = $RemapDivision[%i];
%n = $RemapName[%i];
%c = $RemapCmd[%i];
%start = 0;
if(%n $= %name && %c $= %cmd && (%d $= %div || %lastDiv $= %div))
{
%start = %i + 1;
break;
}
if(%d !$= "")
%lastDiv = %d;
}
if(%start > 0)
{
for(%i=%start; %i < $RemapCount; %i++)
{
$RemapDivision[%i-1] = $RemapDivision[%i];
$RemapName[%i-1] = $RemapName[%i];
$RemapCmd[%i-1] = $RemapCmd[%i];
}
%d = $RemapDivision[%start-1];
if(%d $= "")
$RemapDivision[%start-1] = %div;
$RemapDivision[$RemapCount-1] = "";
$RemapName[$RemapCount-1] = "";
$RemapCmd[$RemapCount-1] = "";
$RemapCount --;
}
}
This removes an existing keybind properly.
removeKeyBind("Division","Name","command");
Division - This division will remain if there are still other binds under it.
Name - The name of the bind.
Command - The command called when this bind is used.
Hope this helps people!