i'm build a function for do the combination of keys(like the kombat games: we do some combination keys for do an actions):
bool CombineKeys(std::vector<int> const keys)
{
static bool PreviousKeyPressed;
static DWORD StartTimer = GetTickCount();
static int i=0;
if((GetAsyncKeyState(keys[0]) & 0x8000) and PreviousKeyPressed==false)
{
i=0;
SetWindowText(a,"hello");
PreviousKeyPressed=true;
i++;
}
else if((i==(int)keys.size()-1) && (GetAsyncKeyState(i) & 0x8000) and PreviousKeyPressed==true)
{
SetWindowText(a,"hi");
return true;
}
else if((GetAsyncKeyState(keys[i]) & 0x8000) and PreviousKeyPressed==true)
{
i++;
PreviousKeyPressed=true;
}
else if(GetTickCount() < (StartTimer + 20000))//2 seconds
{
PreviousKeyPressed=false;
i=0;
}
else
{
PreviousKeyPressed=false;
i=0;
}
return false;
}
//heres how i use in keydown message
if(CombineKeys({'A','B'})==true)
MessageBox(NULL,"hi","hi",MB_OK);
i see some problems with my function :(
seems the i not be plus 1, because only get the 1st if :(
if i press the next letter, don't do nothing :(
what i'm doing wrong?