Game Development Community

How to add an isKeyDown() function

by Joe Spataro · in Torque Game Builder · 06/06/2005 (6:17 pm) · 4 replies

How would one add an isKeyDown() function and expose it to the script.

I searched through actionmap.h/cc and through the platform input stuff but I couldn't really figure out how it all worked.

What I would like to accomplish is to add this function with the intention of trying to use it in place of the bindCmd method of handling the movement of my player character in a beat-em-up game.

#1
06/07/2005 (12:21 am)
I did a similar thing in script. When a key is pressed, I set a variable to true, and call a seperate schedule function to keep looping as long as the variable is true. Once the key is released I set the variable to false and cancel the schedule.

Not sure if that would actually achieve what you want though.
#2
06/07/2005 (9:22 am)
What Philip said should accomplish exactly what you want... you could set it up like this

first the key bind

playerMap.bindCmd(keyboard, "a", "keyDown(\"a\");", "keyUp(\"a\");");

then the commands it calls

function keyDown(%key)
{
   $keyDown[%key] = true;
}

function keyUp(%key)
{
   $keyDown[%key] = false;
}

then the isKeydown function

function isKeyDown(%key)
{
   if(!$keyDown[%key])
      return false;

   return true;
}
#3
06/07/2005 (9:25 am)
Then to load a bunch of keys you can do this

function loadKeyBinds()
{

   %keys = "a b c d e f g h i j k l m n o p";
   %keyCount = getWordCount(%keys);

   for(%i=0;%i<%keyCount;%i++)
   {
      %key = getWord(%keys, %i);
      playerMap.bindCmd(keyboard, %key, "keyDown(\"" @ %key @ "\");", "keyUp(\"" @ %key "\");");
   }
}
#4
06/07/2005 (9:41 am)
Wow. You guys are amazing. Thank you so very much!