LOL... A simple question and a diatribe of why not to cheat. This is a programming forum not an anti-cheating forum. Not sure how far you may have gotten with your project but I hope to be able to contribute some to your learning curve. Hate to bring this topic to the surface and restart the anti-Bot rants so I will ask that any further contributors please get off your soap box and actually contribute towards the goal which is learning PureBasic specifically and learning programming generally.
The needs of a bot vs. the programming of a bot are two different discussions. The concept of programming a bot brings about lots of fun discussions about various methods to obtain optimal performance. Unfortunately, this groups decision is to ridicule instead of investigate.
I on the other hand would rather investigate in order to improve not only the requestor's knowledge but also potentially my own knowledge. So with that said. You are basically wanting a move the mouse type some text bot.
I will assume this is for the windows platform, therefore I will be using some code that I wrote last year which contains Windows API calls. Everything I am contributing I found in the forums in some shape or form and was able to bring together. So hopefully this will consolidate some of the information for you.
Set up some procedures using SetCursorPos_(x,y) along with the mouse_event_() API calls:
Code: Select all
Procedure Click_L_Mouse()
;Simulate mouse click
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0):Delay(7) ;mouse left button down
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0):Delay(7) ;mouse left button back up
EndProcedure
Procedure Click_R_Mouse()
mouse_event_(#MOUSEEVENTF_RIGHTDOWN,0,0,0,0):delay(7) ; Mouse right button down
mouse_event_(#MOUSEEVENTF_RIGHTUP,0,0,0,0):delay(7) ; Mouse right button up
EndProcedure
Procedure MoveMouse(x,y)
SetCursorPos_(x,y)
EndProcedure
Now why do I not use the MouseLocate(x,y) command in PB. Because when I tried it originally back in v3.91 it only worked within the actual PB window. Using the SetCursorPos_(x,y) sets the position on the current desktop and does not look at what may or may not appear under the cursor once set. (I have not used the MouseLocate(x,y) command since v3.91 or so, therefore I do not know if it works more like SetCursorPos_(x,y) or not).
The MouseButton() commands in PB allow you to see if they have been pressed but does not allow you to "virtually" press them thus I use the Windows API mouse_event_() to simulate a mouse click.
For sending key strokes I would use the SendKeys() procedure by PB located here
http://www.purebasic.fr/english/viewtopic.php?t=3766
Now the question is where do you move the mouse to and what to do. A quick an easy program to place a sticky window in the bottom right corner of the desktop to display mouse X and Y positions would be nice.
Something like this should do the job
Code: Select all
;-----------------------------------------------------
;
; MouseLoc.pb
; Date: June 10 2009
; Author: Kevin Perryman
; Version 1.1
;
; V 1.1 06/10/2009
; Added lines to make window sticky to stay on top
;
; V 1.0 06/09/2009
; simply tell us where the mouse cursor is on the
; desktop
;-----------------------------------------------------
;Declare structures
Structure tagPOINT
x.l
y.l
EndStructure
Global POINT.tagPOINT
;--------------------
;Main program
;--------------------
; Get the resolution of the desktop
ExamineDesktops()
DT_Width=DesktopWidth(0)
DT_Height=DesktopHeight(0)
; Figure out where to place window to display mouse coordinates
Win_Width=90
Win_Height=20
Pos_x=DT_Width-Win_Width-22
Pos_y=DT_Height-Win_Height-52
; create window in which we will display the mouse coordinates
MyWindow=OpenWindow(0, Pos_x, Pos_y, Win_Width, Win_Height, "Mouse Loc", #PB_Window_SystemMenu )
If MyWindow
txt_titlex=TextGadget(#PB_Any,5,5,10,20,"X:")
txt_MouseX=TextGadget(#PB_Any,20,5,40,20,"0.00")
txt_titley=TextGadget(#PB_Any,60,5,10,20,"Y:")
txt_MouseY=TextGadget(#PB_Any,75,5,40,20,"0.00")
EndIf
;Keep window on top of all other windows
StickyWindow(MuWindow,1)
; setup a variable to check for program close
CLOSEME=0
Repeat
;keep window on top
; check to see if window X has been pressed
e=WindowEvent()
If e=#PB_Event_CloseWindow
CLOSEME=1 ; if window X has been pressed set variable to end loop
EndIf
; Get Cursor Position
GetCursorPos_(@POINT)
MouseX$=Str(POINT\x)
MouseY$=Str(POINT\y)
;Update Cursor Position in Output window
SetGadgetText(txt_MouseX,MouseX$)
SetGadgetText(txt_MouseY,MouseY$)
; ;smoother update of mouse coordinates and also release CPU to other processes
;basically helps prevents system resource hogging
Sleep_(70)
Until CLOSEME ; if CLOSEME then lets exit and end the program
End
Now with this program running just open your game. Move the mouse and pause a moment to jot down the mouse cursor locations that are needed. Note anytime you need to type something from the keyboard and you have the basic information to move the mouse around and type.
You now codify your bot by writing program code that moves the mouse, clicks as appropriate and types keyboard input as needed. Being sure to place delays and pauses for correct timing.
Should be relatively easy as all you have to do is call the appropriate procedure from above and as needed.
For example you might have something like this (from my autologin program):
Code: Select all
MoveMouse(545,708)
Click_L_Mouse()
Click_L_Mouse() (call twice to simulate double click)
Delay(50)
For i = 1 To 20
PressKeys(hWnd,backspace$) (clear out the field)
Next i
PressKeys(hWnd,username$) (type in a username)
; relocate mouse cursor to password box
MoveMouse(542,731)
Click_L_Mouse() ; single click to place cursor in password box
For i = 1 To 20
PressKeys(hWnd,backspace$) ; clear password box
Next i
PressKeys(hWnd,password$) ; enter password
; Move mouse to login button
MoveMouse(513,752)
Click_L_Mouse()
Delay(5000) ; wait for program/website to load
This is a dumb program meaning it will only do what you have previously done at least once. If you do it multiple times and it is very repetitive then this will work. If on the other hand, you want something to figure out where to entrance/door is, open it, move through it, look for monsters, check health and make sure I can fight safely, engage monster, look for next room, etc. then as pointed out by superadnim you would need to monitor memory blocks which will really add lots of intelligence to the bot but at the same time get way, way complicated.
Good luck on your project... feel free to PM me for specific questions.
Slyvnr