gpt4 book ai didi

c++ - GetAsyncKeyState 不工作

转载 作者:行者123 更新时间:2023-11-28 05:52:20 30 4
gpt4 key购买 nike

我是 C++ 的新手,因为我对 Java/Python 等更有经验。但是,我一直在尝试实现一个简单的 Trigger Bot,但添加了一个故障保护,这样如果我按下某个键,程序将调用 exit(0) 方法。但是我实现按键输入的方式似乎不起作用,有人可以帮助我吗?

void MainScan(Contents scan) {
#if DB
int debug = clock();
#endif
while (true) {
for (int y = scan.startY; y < scan.compareY; y++) {
for (int x = scan.startX; x < scan.compareX; x++) {
//SetCursorPos(x, y);
if (GetAsyncKeyState(VK_DELETE)) {
exit(0);
}
}
}
}
}

最佳答案

使用方法如下:https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx

这是我的一个基于控制台的迷宫游戏的旧项目的代码片段:

Difficulty AskDifficulty() {
// xy norm = 1, 2 y++ for rest
point base(1, 2);
drawatxy(1, 2, '*');
while (GetAsyncKeyState(VK_RETURN)) // while it is being pressed, do not consider any input until we let go of the key
g_delay(0.001);
while (true) { // now we let go of it, consider inputs once more
if (GetAsyncKeyState(VK_RETURN) & 0x8000) {
switch (base.y) {
case 2:
return DIFF_EASY;
case 3:
return DIFF_NORM;
case 4:
return DIFF_HARD;
default:
return DIFF_INVALID;
}
}
else if (GetAsyncKeyState(VK_DOWN) & 0x8000) {
if (base.y < 4) {
drawatxy(1, base.y, ' ');
base.y++;
drawatxy(1, base.y, '*');
g_delay(0.125);
}
}
else if (GetAsyncKeyState(VK_UP) & 0x8000) {
if (base.y > 2) {
drawatxy(1, base.y, ' ');
base.y--;
drawatxy(1, base.y, '*');
g_delay(0.125);
}
}
else
_getch();
}
}

关于c++ - GetAsyncKeyState 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34968895/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com