I have the following code which works fine.
int x = 0;
int main()
{
while(true) {
if (GetKeyState('A') & 0x8000 && x == 0) {
Sleep(500);
x = 1;
}
else if (GetKeyState('B') & 0x8000 && x == 1) {
Sleep(500);
x = 2;
}
else if (GetKeyState('C') & 0x8000 && x == 2) {
Sleep(500);
x = 0;
//Do Something
}
}
}
In order to execute the //Do Something
part of the code, the user must first press A
, then B
and then C
in that order. However the user can press any key in between and it will still work. So in addition to "A
+B
+C
" the following will also work.
A
+C
+B
+C
A
+Q
+B
+C
A
+F11
+B
+8
+LSHIFT
+Spacebar
+Tab
+C
I want only the A
+B
+C
combination to work. Not any of the above.
The code I am trying to implement is somewhat like this
int x = 0;
int main()
{
while(true) {
if (GetKeyState('A') & 0x8000 && x == 0) {
Sleep(500);
x = 1;
}
else if (GetKeyState('B') & 0x8000 && x == 1) {
Sleep(500);
x = 2;
}
else if (GetKeyState(/*Any keyboard input other than 'B' or 'A'*/) & 0x8000 && x == 1) {
Sleep(500);
x = 0;
}
else if (GetKeyState('C') & 0x8000 && x == 2) {
Sleep(500);
x = 0;
//Do Something
}
else if (GetKeyState(/*Any keyboard input other than 'C' or 'B'*/) & 0x8000 && x == 2) {
Sleep(500);
x = 0;
}
}
}
So you see I understand the logic required. I just don't know the correct code required to replace the commented part of my code. Please note that the reason I have entered two keys in the comments is because the user might accidentally press a key twice or thrice for which he/she needs to be excused and code needs to still work.
I think I have tried my best to make this question as understandable as possible. If not feel free to suggest edits.