gpt4 book ai didi

c++ - AutoclickerInGame - 为什么不工作?

转载 作者:行者123 更新时间:2023-11-28 05:09:00 25 4
gpt4 key购买 nike

我正在尝试做一个在游戏打开时自动按下按键的机器人。在记事本中这个程序运行良好,但在 Metin2 中它什么也不做。你有什么想法,有什么问题吗?

int main()
{
clock_t start = clock();
clock_t start_grab = clock();
HWND handle = NULL;
handle = FindWindow(0, "PandoraMT2.pl");
if (handle != 0)cout << "well";
for (int i = 0; i < i + 1; ++i)
{
handle = GetActiveWindow();
// SendMessage(handle, WM_CHAR, VK_SPACE, 0);
if ((clock() - start) / (double)CLOCKS_PER_SEC == 1)
{
keybd_event(VK_SPACE, 0, 0 , 0);
keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
start = clock();
}
if ((clock() - start_grab) / (double)CLOCKS_PER_SEC == 6)
{
keybd_event(VkKeyScan('Z'), 0, 0, 0);
keybd_event(VkKeyScan('Z'), 0, KEYEVENTF_KEYUP, 0);
start_grab = clock();
}
}

最佳答案

游戏的键状态/鼠标状态可能不依赖于 Windows 消息队列。例如Windows 中的两个可能的选择是:

GetKeyState

GetAsyncKeyState

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).aspx

来自 GetKeyState:

The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.

因此,GetKeyState 是根据消息队列中发生的情况来读取状态,而 GetAsyncKeyState 是直接读取硬件中断(无论物理键是按下还是按下,包括鼠标键)。消息队列支持输入缓冲,例如队列中的键可能会滞后。出于这个原因,许多游戏开发者可能更喜欢将 GetAsyncKeyState 用于实时游戏,并且这些游戏不会收到您的假按键事件。

关于c++ - AutoclickerInGame - 为什么不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43938214/

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