4ng3licDew Cheater
Reputation: 0
Joined: 14 Feb 2008 Posts: 28
|
Posted: Sat Feb 23, 2008 10:35 am Post subject: C/C++ Auto Click using PostMessageA + 5 Tutorial |
|
|
Hi everyone,
First I would like to thanks everyone who had contributed at Cheat Engine Forum. As my way of saying thank you I am going to show you how to write your own auto click program.
I have created an AutoClick program for MapleStory Global, using Microsoft Visual Studio C++ 6.0 and win32.
This program generates 'control' key down events, 'z' key down events, 't' key down events, and left mouse double click events.
To better understand what I am about to discuss here you will need:
1. to know C/C++
2. to have a basic understanding of how to create a Win32 program. For a tutorial on Win32 Fundamental please google "win32 tutorial" (Sorry I can't post a link yet).
Here is what I did:
1. Create my own PostMessageA function, using a well known technique PostMessage + 5 that has been discussed here at Cheat Engine Forum. You will need to load user32 DLL at start up. Then get a function pointer to PostMessageA and add 5 bytes to this function pointer.
| Code: |
HINSTANCE hInst; // Instance of user32 DLL
DWORD DLLFunc; // PostMessageA + 5
.
.
.
// PostMessageA + 5 bypass
__declspec(naked) BOOL WINAPI myPostMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
__asm
{
mov edi, edi
push ebp
mov ebp, esp
jmp dword ptr ds:[DLLFunc]
}
}
.
.
.
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
.
.
.
case WM_CREATE:
m_hInst = LoadLibrary("user32.dll");
DLLFunc = NULL;
if (m_hInst != NULL) {
DLLFunc = (DWORD)GetProcAddress(m_hInst, "PostMessageA") + 5;
}
.
.
.
|
2. To unload user32 DLL when AutoClick terminates.
| Code: |
.
.
.
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
.
.
.
case WM_DESTROY:
if (m_hInst != NULL) {
// Un-Load DLL
::FreeLibrary(m_hInst);
m_hInst = NULL;
}
.
.
.
|
3. To generate a 'Control' key down event or a mouse double click event.
| Code: |
HWND m_cHandle; // Windows handle to MapleStory
.
.
.
void SendKey(UINT vk_key) {
UINT scancode;
LPARAM lparam;
// Get window handle on MapleStory
m_cHandle = ::FindWindow("MapleStoryClass", NULL);
if ((m_cHandle != NULL) && (DLLFunc != NULL)) {
// map virtual key code to scan code
scancode = MapVirtualKey(VK_CONTROL, 0);
// The scancode value is in the low 16 bits
// need to shift it to the left 16 bits.
// + 1 is the repeat count
lparam = (scancode << 16) + 1;
myPostMessageA(cHandle, WM_KEYDOWN, NULL, lparam);
myPostMessageA(cHandle, WM_KEYUP, NULL, lparam);
// This call will only generate key press in textboxes
//myPostMessageA(cHandle, WM_KEYDOWN, vk_key, NULL);
//myPostMessageA(cHandle, WM_KEYUP, vk_key, NULL);
// This call will generate key press in both textboxes
// and the graphic screen.
//myPostMessageA(cHandle, WM_KEYDOWN, vk_key, lparam);
//myPostMessageA(cHandle, WM_KEYUP, vk_key, NULL);
}
}
// Send left mouse button double click
void SendDoubleClick(void) {
if (cHandle == NULL) {
// Get window handle on MapleStory
cHandle = FindWindow("MapleStoryClass", NULL);
}
if ((cHandle != NULL) && (DLLFunc != NULL)) {
// Get mouse cursor position
GetCursorPos(&Pos);
myPostMessageA(cHandle, WM_LBUTTONDOWN, NULL, (LPARAM)&Pos);
myPostMessageA(cHandle, WM_LBUTTONUP, NULL, (LPARAM)&Pos);
myPostMessageA(cHandle, WM_LBUTTONDBLCLK, NULL, (LPARAM)&Pos);
myPostMessageA(cHandle, WM_LBUTTONUP, NULL, (LPARAM)&Pos);
}
}
.
.
.
// generate a 'Control' key down event
SendKey(VK_CONTROL);
// generate left mouse double click event
SendDoubleClick();
.
.
.
|
4. To Add hot key Control + F9 to toggle auto click on or off. You need to register the hot key at start up, and unregister the hot key when the program terminates. Then add an event handler for when the hot key is pressed. This event handler will toggle the auto click on or off.
| Code: |
UINT m_nIDHotKey1; // Hot key identifier
.
.
.
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
.
.
.
case WM_CREATE:
// Register "Ctrl + F9" as my hot key
nIDHotKey1 = GlobalAddAtom("AutoClick1");
RegisterHotKey(hWnd, nIDHotKey1, MOD_CONTROL, VK_F9);
.
.
.
case WM_DESTROY:
// Un-Register my hot key
UnregisterHotKey(hWnd, nIDHotKey1);
.
.
.
case WM_HOTKEY:
// (Ctrl + F9) Auto Click 1
if (wParam == nIDHotKey1) {
// Toggle timer on or off here
return 0;
}
.
.
.
|
5. To create timer and timer callback.
| Code: |
#define ID_TIMER1 2
int nTimer1on; // Flag indicating timer1 is on/off
.
.
.
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
int interval;
.
.
.
case WM_CREATE:
// Set timer flags to off
nTimer1on = 0;
.
.
.
case WM_HOTKEY:
// (Ctrl + F9) Auto Click 1
if (wParam == nIDHotKey1) {
if (nTimer1on == 0) {
nTimer1on = 1;
interval = 350; // set auto click at every 350 milli seconds interval
// Create timer
SetTimer(hWnd, ID_TIMER1, interval, NULL);
} else {
nTimer1on = 0;
// Destroy timer
KillTimer(hWnd, ID_TIMER1);
}
return 0;
}
.
.
.
case WM_TIMER:
if(wParam == ID_TIMER1) {
// Send key down event
SendKey(VK_CONTROL);
return 0;
}
.
.
.
|
I hope this will help you in your future coding endeavor
I have attached the source code in this reply for all you programmers out there. Enjoy!
| Description: |
| Snap shot of AutoClick GUI. |
|
| Filesize: |
64.33 KB |
| Viewed: |
14243 Time(s) |

|
|
|