Game Development Community

Detect if any key is pressed

by James Tracey · in Torque Game Engine · 01/25/2006 (8:00 am) · 4 replies

Is there a way to detect if any key is pressed, get the key id, and state of the key?
I want to run keys 0 - 9 threw a switch case statement.
Thanks in advance.

#1
02/09/2006 (6:09 pm)
From script, or c++?

B--
#2
02/10/2006 (11:38 am)
If script, one way and maybe not ideal is to set up bind maps for 0-9

// bind for key 0
moveMap.bind(keyboard, "0", SetKeyState_0);

function SetKeyState_0(%val)
{
    $keystate[0] = %val;
}
...
// bind for keys 1...9

Then you can check $keystate anywhere in script.

-Jeff
#3
02/10/2006 (12:00 pm)
You can also use bindCmd and actualy use a switch statement(you also avoid redundant functions):

seatMap.bindCmd(keyboard, "F1", "KeySwitch(0);", "");
seatMap.bindCmd(keyboard, "F2", "KeySwitch(1);", "");
seatMap.bindCmd(keyboard, "F2", "KeySwitch(2);", "");
ect...

function KeySwitch(%keyNum)
{
switch(%keyNum) {
.......
};
}
#4
02/12/2006 (3:50 pm)
Thanks Josh, That looks good, it will save me from using redundant functions, like you said.