Game Development Community

Key Combos

by Joel Hargarten · in Torque Game Engine · 07/21/2005 (12:14 pm) · 2 replies

Hey,
I want to throw out a question to anyone who knows how to do this. I'm setting up the controls for my game and I want to know how to have it so that when a combination of keys are pressed at the same time, an animation plays. I can play the animation by binding one key to it, but I dont know how to do it with a combination. For example, lets say I have an attack move that is triggered by the combination: "ctrl + d + right" how would I do that and where.

Here is something else. Let's say I had an attack that has to be a series of keys before it plays. For example: "ctrl + a + left" followed by the "down" key. Thanks.

#1
07/21/2005 (2:04 pm)
Well you need to have a function that monitors if the keys are pressed or not. i use a buttonmonitor function for that with my gamepad. when buttons are pressed..... all they do is create a flag=true.
when the key is released, the flag is turned off. It may also be helpful to tag it so you know when the button was pressed... like if you have to presses buttons with a pause needed... maybe also make it time out the button presses if you press it too long and don't do anything.


my buttonmonitor functions will check to see what flags are true.
here's some psuedo code.

function buttonmonitor(){

if (buttona && buttonb)
dojumpkick()
return;

if (buttonz && buttonb)
plantrosesk()
return;

if (buttonctrl && buttonalt && buttondel)
resetPC()
return;



schedule(10,0,buttonmonitor)

}
#2
07/21/2005 (2:34 pm)
I would say that you need some sort of class that sits between the key processor and they input device. It would record keys as they are pressed and store them into a queue. Store all of your key combos by length (2 keys, 3 keys, 4, 5, and 6, etc..) and then compare the last x keys to your combo lists. If a match is found, call some sort of registered callback in script or C++ code. That shouldn't be too hard to implement.

For key codes that build off of eachother (i.e. -- a 6 key combo that consists of an existing 3 key combo and another 3 keys) you may need to put in some delayed processing to allow them to get off all 6 keys and not start the processing for the 3 key combo.

- Brett