Game Development Community

Detecting Key release

by Rob Riddell · in Torque Game Engine · 04/27/2005 (10:01 pm) · 3 replies

I am working on facial animations. I have created new key maps to trigger new cel animations when the key is pressed. example, raised eyebrows. or Pointing.

My next desire is that I want to hold the key down to keep the eyebrows raised or the arm raised. When I release the key, I want to detect that and trigger the next animation that will return to a un raised eyebrow.

Sample function in default.bind.cs

function playpoint(%val)
{
if (%val)
echo("Pointed!! ");
commandToServer('playCel',"point");
}
movemap.bind(keyboard, "ctrl m", playpoint );

this works on my model created in MilkShape3D and exported with the current GG milkShape2DTS exporter.

the key bind I use is ctrl m

I have played around with the frame sequences as cyclic and not cyclic, some as single frames or multiple frames. To my mind, having one frame labelled celpoint and then having the function call that single frame sequence , then a function that would detect the key release and move the animation to a single frame that has the arm not pointing would be great.

Is this detectable? Do I have to dream up code? I know that whenever the key is press, the %val is set to true. Tried the following code in default.bind.cs also :

function playsalut(%val)
{
if (%val)
echo(%val);

if ($Ctrls != 1)
{
$Ctrls = 1;
echo("CtrlS == 1 !");
echo($CtrlS);

}

echo("Pressed ctrl s!! ");
echo("-----");
commandToServer('playCel',"salute");

if ($CtrlS == 1)
{
echo("CtrlS == 1 Now!");
$ctrlS = 0;
echo("CtrlS == 0 Then! " @ $ctrlS @ " msg1");
echo("*****");


}
}

All the echoes are to try and figure out what state the key press is at and what I see on screen.

Do I have to edit the code and recompile or can I do this in torque script?

Have I missed a resource when searching the forums and resources?

Thanks in advance for any ideas from anyone.

Smiles . . .

#1
04/27/2005 (10:41 pm)
When you release the key, it would run the same function, but %val would be 0.
#2
04/28/2005 (4:04 pm)
Or you can use bindCmd

movemap.bind(keyboard, "ctrl m", "playpointkeydown();","playpointkeyUp();");

Here is the function framework for a regular bind:

movemap.bind(keyboard, "ctrl m", playpoint );


function playpoint(%val)
{
	if (%val)
	{
		echo("The key is down");	
	}
	else
	{
		echo("The key was released");
	}
}
#3
04/29/2005 (10:23 pm)
Thank-you ! Terrific help.