cuốn sách gpt4 ai đã làm

c++ - 键鼠监听,自动化

In lại Tác giả: Walker 123 更新时间:2023-11-28 03:32:31 30 4
mua khóa gpt4 Nike

我想为一款名为 Dune 2000 的策略游戏创建一个叠加层。令人讨厌的是,要创建 10 个士兵,每次完成一个都必须单击该图标。没有队列。因此,在不干扰游戏运行方式的情况下,我想听听鼠标移动的声音,当在 XY 位置进行点击时,我希望重复十次,例如在正确的时间间隔。是否有任何图书馆允许我这样做?

câu trả lời hay nhất

下面是鼠标右键的自动点击器代码。对于鼠标左键使用mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);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;
}

关于c++ - 键鼠监听,自动化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12070410/

30 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress