|
Controlling Mouse Droppings
We can cause the same effect with the mouse because, just like a keyboard, the mouse generates events as you use it. By sending these events to the game client, we can make it believe that a user is wielding the mouse.
The following source code snippet illustrates use of the mouse_event API call with some inline commentary.
DWORD LMouseClick(DWORD x, DWORD y, bool shift)
{
int ix,iy;
This code gets the width and height, in pixels, of the monitor or screen.
ix=GetSystemMetrics(SM_CXSCREEN);
iy=GetSystemMetrics(SM_CYSCREEN);
This code converts the client coordinates of the foreground window to screen coordinates, letting you move the game client window around—thereby avoiding the annoying problem of having to align the game client screen to the upper left corner of the monitor. Some macro programs require this, but here we show you how to avoid that annoyance.
POINT p;
p.x = x;
p.y = y;
ClientToScreen(GetForegroundWindow(), &p);
The mouse_event call requires you to specify the coordinates in mikeys—the screen is divided into 65,536 (16 bits) mikeys for both x- and y-coordinates—so the upper left is (0,0) and the lower right is (65535, 65535).
DWORD mikeysX = p.x * 65535 / ix;
DWORD mikeysY = p.y * 65535 / iy;
This sets the mouse position on the screen.
mouse_event(
MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE,
mikeysX,
mikeysY,
0, 0);
If you want, you can specify that the shift key is pressed before the mouse event. This is useful, for example, when you need to shift-right-click to auto-loot a bag and so on.
if(shift)
{
keybd_event(
VK_LSHIFT,
MapVirtualKey(VK_LSHIFT, 0), 0, 0);
The sleep here is optional; you may want to experiment with your target game.
//Sleep(20);
}
You can substitute a parameter here to make this a right click instead of a left click. Look up the documentation on mouse_event to see all the available options.
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
//Sleep(20);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
//Sleep(20);
If we used the shift, let’s put it back now.
if(shift)
{
keybd_event(
VK_LSHIFT,
MapVirtualKey(VK_LSHIFT, 0), 0 |
†††††††††††††††††††††††††††KEYEVENTF_KEYUP, 0);
//Sleep(20);
}
return 0;
}
As you can see, wielding the mouse is just as automatic and easy as wielding the keyboard. This is a classic technique that’s as old as the hills.
3. We know that everyone has their own opinions on matters such as these; this is just our own studied opinion.
|