我有以下代码可以正常工作。
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
}
}
}
为了执行这//Do Something部分代码,用户必须先按A,然后B按此C顺序。但是,用户可以在两者之间按下任何键,它仍然可以工作。因此,除了“ A++ ”B之外C,以下内容也可以使用。
A+C+B+CA+Q+B+CA+F11+B+8+LSHIFT+Spacebar+Tab+C
我只希望++A组合起作用。以上都不是。BC
我试图实现的代码有点像这样
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;
}
}
}
所以你看我理解所需的逻辑。我只是不知道替换代码的注释部分所需的正确代码。请注意,我在评论中输入两个键的原因是用户可能不小心按了一个键两次或三次,为此他/她需要被原谅并且代码仍然需要工作。
我想我已经尽力使这个问题尽可能容易理解。如果不能随意提出修改建议。