char*
GetKeys ()
{
const int key_reg[] = {KEY_RIGHT, KEY_LEFT, -1}; // must end with -1
// list of keys that can have keyup states
// that way it doesn't need to loop through every key
// because rarely do people want to catch gp2x keys
// static variables are only initialized once
static int protect = 0; // used to lock the function (only once per frame)
static char key_prev[500] = {0}; // or however long GetKeyState is
static char* key; // function remembers last key state
if(frame%2==protect) // only update once per frame
{
int i;
key=GetKeyState();
for(i=0; key_reg[i]!=-1; i++) // loop through registered keys
{
if(key_prev[key_reg[i]]==1 && key[key_reg[i]]==0)
{ // if the key was pressed, but isn't anymore
key_prev[key_reg[i]]=key[key_reg[i]]; // set key previous
key[key_reg[i]]=-1; // set to keyup
}
else
{
key_prev[key_reg[i]]=key[key_reg[i]]; // set key previous
}
}
protect=protect==0; // lock until next frame
}
return key;
}
Users browsing this forum: No registered users and 1 guest