Author Topic: what command can i use to manually set a keybind?  (Read 693 times)

Suppose I have a GUI function that opens up a GUI, like
Code: [Select]
function openGUI(%)
{
canvas.pushdialog(yourMom);
}

what can i put in client.cs that automatically sets a keybind for the function?

Put this in your file somewhere:


$remapDivision[$remapCount]   = "Add-on name";
$remapName[$remapCount]      = "Keybind name";
$remapCmd[$remapCount]      = "function to call (you would put openGUI)";
$remapCount++;


So when someone sets this keybind and presses the button, it's going to automatically call your "openGUI" function with a 1 as a parameter. It's going to do openGUI(1); when you push down and openGUI(0); when you let up. This means you'll have to have a variable in your function named something like %on so you can tell the difference between it being pushed down and let up. Doing something like if(!%on) return; will prevent the function from being called twice when you only want it once.

Not sure what you're doing at the top of your code with the lonely % but if you wanted to include a variable it'll need a name.

few examples

forced keybind
Code: [Select]
GlobalActionMap.bindCmd(keyboard, "f6", "", "toggleBGMusicGui();");

simple custom keybind
Code: [Select]
if (!$AutoJet::addedJet)
{
$remapDivision[$remapCount] = "Auto-Jet";
$remapName[$remapCount] = "Activate/Deacticate";
$remapCmd[$remapCount] = "activateJet";
$remapCount++;
$remapName[$remapCount] = "Elevate";
$remapCmd[$remapCount] = "autoJetHeightUp";
$remapCount++;
$remapName[$remapCount] = "Decend";
$remapCmd[$remapCount] = "autoJetHeightDown";
$remapCount++;
$AutoJet::addedJet = true;
}

more complex custom keybind (can add to existing divisions)
Code: [Select]
//Hug toggle, keybind code ripped from Ephialtes' quicksave, and commandtoserver('unusetool'); was suggested by Ephialtes
//Stolen from Ephialtes who stole from Randy
function AddBind(%division, %name, %command)
{
for(%i=0;%i<$remapCount;%i++)
{
if($remapDivision[%i] $= %division)
{
%foundDiv = 1;
continue;
}
if(%foundDiv && $remapDivision[%i] !$= "")
{
%position = %i;
break;
}
}
if(!%foundDiv)
{
error("Division not found: " @ %division);
return;
}
if(!%position)
{
$remapName[$remapCount] = %name;
$remapCmd[$remapCount] = %command;
$remapCount++;
return;
}
for(%i=$remapCount;%i>%position;%i--)
{
$remapDivision[%i] = $remapDivision[%i - 1];
$remapName[%i] = $remapName[%i - 1];
$remapCmd[%i] = $remapCmd[%i - 1];
}
$remapDivision[%position] = "";
$remapName[%position] = %name;
$remapCmd[%position] = %command;
$remapCount++;
}

if(!$HugToggleBound)
{
AddBind("Emotes", "Hug", "togglehug");
$HugToggleBound = true;
}

edit:
here's a bit more of the BGMusic GUI opening/closing code, in case it helps you
Code: [Select]
GlobalActionMap.bindCmd(keyboard, "f6", "", "toggleBGMusicGui();");

function toggleBGMusicGUI()
{
   if(BGMusicGui.isAwake())
      canvas.popDialog(BGMusicGui);
   else
      canvas.pushDialog(BGMusicGui);
}
« Last Edit: May 30, 2017, 09:08:10 PM by phflack »

few examples

forced keybind
Code: [Select]
GlobalActionMap.bindCmd(keyboard, "f6", "", "toggleBGMusicGui();");

simple custom keybind
Code: [Select]
-snip-

Thank you.
« Last Edit: May 31, 2017, 06:25:06 AM by theviacom »