Shifu-Hacks Blog

愚かさは博学ではない。

Simple bot creation (Part 2/3)

Posted by compactwater on September2 2007

Editor’s note: This is only a small sample and explanation of usage.

Now you know how to click. And you probably want to type something, or press a key, to make your bot better! It’s simple, but there’s many ways to do it, so you’ll have to find the best method for your needs. Something you should never do, is have the game loaded in your program, and give input to the game like that. It usually always leads to slow game-play, and crashing. Keep that in mind when making a bot, always think ahead, so you don’t get lost and have to start all over.

SendMessage or PostMessage can be used to Send or Post a message (who knew?). Remember to choose which one will be best for your use, if you don’t understand the difference, click here for more information. When using S/PMessage, you should always use error handling (try, except, finally) in case of an error. If something were to go wrong, your application may crash or become unstable- never let this happen, use error handling! It’ll look something like this:

try //start something
HAND:=FindWindow(nil, PChar(Edit1.Text)); //Find the window
MySayso:=StrToInt(Edit2.Text); //Set the message. You may want to use Cardinal instead of Integer.
SendMessage(HAND, MySayso, 0, 0); //Send the message
except //If there’s an error…
on error: Exception do
MessageBox(Self.Handle, PChar(String(error.Message)), PChar(String(error.ClassName)), MB_OK); //Show what (if anything) went wrong.
end;

With that, the user can specify a message to send to anyother window, and if there’s a problem sending the message, the program won’t crash so easily. If you’re a beginner, you should stick to “mouse_input” and “Send/PostMessage”, SendInput can be a bit complicated, and if not used correctly, cause many errors. Personally, I only use simple functions in my projects, unless it’s a larger project. Torry’s Delphi Pages may be of more help on SendInput, and other functions.

Pixel Detection will be next, It will be more detailed as well.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: