0

我正在寻找一个名为 Dune 2000 的策略游戏的叠加层。创建 10 名士兵很烦人,每次完成时都必须单击图标。没有队列。因此,在不干扰游戏运行方式的情况下,我想听鼠标的移动,当在位置 XY 上单击时,我想重复例如十次,中间有正确的时间。有没有允许我这样做的库?

4

1 回答 1

2

下面是鼠标右键的 Autoclicker 代码。对于鼠标左键,使用 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

bool KeyIsPressed( unsigned char k )
{
    USHORT status = GetAsyncKeyState( k );
    return (( ( status & 0x8000 ) >> 15 ) == 1) || (( status & 1 ) == 1);
}

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd )
{

    MessageBox( NULL, "[CTRL] + [SHIFT] + [HOME]: Start/Pause\n [CTRL] + [SHIFT] + [END]: Quit", "Instructions", NULL );
    HWND target = GetForegroundWindow();

    POINT pt;
    RECT wRect;
    int delay;
    bool paused = true;

    srand( time(NULL) );

    while ( 1 )
    {
        if ( KeyIsPressed( VK_CONTROL ) && KeyIsPressed( VK_SHIFT ) && KeyIsPressed( VK_HOME ) )
        {
            paused = !paused;
            if ( paused )
            {
                MessageBox( NULL, "Paused.", "Notification", NULL );
            }
            else
            {
                cout << "Unpaused.\n";
                target = GetForegroundWindow();
                cout << "Target window set.\n";
            }
            Sleep( 1000 );
        }

        // Shutdown.
        if ( KeyIsPressed( VK_CONTROL ) && KeyIsPressed( VK_SHIFT ) && KeyIsPressed( VK_END ) )
        {
            MessageBox( NULL, "AutoClicker Shutdown.", "Notification", NULL );
            break;
        }

        if ( paused == false && GetForegroundWindow() == target )
        {
            GetCursorPos( &pt );
            GetWindowRect( target, &wRect );

            // Make sure we are inside the target window.
            if ( pt.x > wRect.left && pt.x < wRect.right && pt.y > wRect.top && pt.y < wRect.bottom )
            {
                mouse_event( MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 );
                mouse_event( MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 );
            }
            delay = (rand() % 3 + 1) * 100;
            Sleep( delay );
        }
    }

    return 0;
}
于 2012-08-22T14:10:57.790 回答