我想为一款名为 Dune 2000 的策略游戏创建一个叠加层。令人讨厌的是,要创建 10 个士兵,每次完成一个都必须单击该图标。没有队列。因此,在不干扰游戏运行方式的情况下,我想听听鼠标移动的声音,当在 XY 位置进行点击时,我希望重复十次,例如在正确的时间间隔。是否有任何图书馆允许我这样做?
下面是鼠标右键的自动点击器代码。对于鼠标左键使用mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Và mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
.
#include
#include
#include
#include
sử dụng không gian tên 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 );
}
khác
{
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 );
phá vỡ;
}
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 );
}
}
trả về 0;
}
Tôi là một lập trình viên xuất sắc, rất giỏi!