Game Development Community

Binding functions to modifier keys

by daffodilistic · in Torque Game Builder · 11/02/2010 (5:09 am) · 5 replies

Hi all,

Just wondering if there is a way to bind modifier keys (Shift, Ctrl, Alt) as normal keypresses in TGB without modifying the source code? It would really be of help to us since we're planning to use Shift/Ctrl/Alt for use in our game.

#1
11/07/2010 (9:04 am)
I'd like to extend the author's request to any tips towards this matter, even if they require modifying the source code.
#2
11/09/2010 (1:23 am)
Seems that its possible to bind Shift/Ctrl/Alt in TGB v1.7.5:

moveMap.bindCmd(keyboard, "lshift", "testModifier(1);", "testModifier(0);");

function testModifier(%value)
{
	echo("Modifier detection success!");
	
	if (%value == 1)
	{
		echo("key is down!");
	}
	else
	{
		echo("key is up!");
	}
}

The code above should do the trick. However, this introduces the problem of StickyKeys, and problems with the breakCmd. In my case, the breakCmd does not fire when you press a key combo, e.g. Shift, followed by D to fire and then move right, will not fire breakCmd when D is released. The fix, thankfully, is simple.

In actionMap.cc, ActionMap::processAction(const InputEvent* pEvent), where the line reads:
pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst );

change it to:
//if modifier is not empty, pass empty modifier to findNode() so that keys will work independantly of modifiers
	  if (pEvent->modifier != 0)
		pNode = findNode( pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objInst );
	  else
		pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst );

Lastly, for StickyKeys, refer to the reference implementation from Microsoft.
#3
11/09/2010 (6:16 pm)
Thank you very much for the help! I've been trying to figure this out for a long time.
#4
07/17/2012 (7:54 am)
I've been having this issue with TGB 1.7.6 with PSK 1.2 and I'm not entirely sure how to fix it. I followed the above instructions to modify actionMap.cc, recompiled TGB and then copied TGBGame.exe out of \tgb\gameData\T2DProject and into my game's project directory to be used as the new executable. However the problem still seems to be persisting as, for example, if while holding down shift I pretty a key to move and then release the move key while still holding down shift the character continues on his merry way until I release shift, press the move key down again and release it.

Do I need to do anything else besides copying over the new .exe? Do any of the files from \tgb\gameData\T2DProject\common or \tgb\gameData\T2DProject\templates also need to be brought over into my project? I also tried creating a new project from scratch to see if maybe it was just an issue with my project created before I applied the fix but no dice, the issue was still there too.

Any help you guys can give would be much appreciated. I'm not entirely sure why anyone would want modifier keys to behave this way in a game environment as I've certainly never seen something like this.
#5
07/17/2012 (12:02 pm)
Whoops, I just realized that I was only rebuilding TGBGame_DEBUG.exe and not the release version that I was trying to run against. Now that I've compiled both debug and release everything is working great! Thanks!