I am looking to create an overlay to a strategy game called Dune 2000. It is annoying that to create 10 soldiers, you have to click the icon everytime one is completed. There is no queue. So without interfering in how the game works, i would like to listen to the mouse movements, and when a click at position XY is made, i would like that to repeat for example ten times, with the right time inbetween. Is there any libary that allows me to do that?
Asked
Active
Viewed 1,098 times
0
-
Are you on Windows? Google for `WH_MOUSE_LL` and `WH_KEYBOARD_LL`. – tenfour Aug 22 '12 at 11:25
-
You should have a look at [AutoHotKey](http://www.autohotkey.com/), it may be a more appropriate tool for this sort of task. – Mankarse Aug 22 '12 at 11:48
-
are you looking for a machine learning application or you will fire your script when needed without any need of learning process? – Seçkin Savaşçı Aug 22 '12 at 14:25
-
just a sort of automation for mouse and keyboard while still having input from the user. For example, every second the mouse remembers its positions, jumps to some XY clicks, and returns allowing user input again. – Bartlomiej Lewandowski Aug 22 '12 at 15:05
-
I'm sure you've already discovered this on your own, but for reference to anyone who stumbles upon this question: This kind of thing is often seen as cheating. – Nic Sep 28 '15 at 16:53
1 Answers
2
Below is a Autoclicker code for the right mousebutton. For the left mouse button use
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
and 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;
}

Software_Designer
- 8,490
- 3
- 24
- 28