 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Zed Gecko
Joined: 23 Sep 2006 Posts: 98
|
Posted: Fri Jul 06, 2007 7:45 am Post subject: 4 Game Automation: FUNCTIONS(e.g. random click) and TOOLS |
|
|
I have created some basic stuff for the game automation fraction.
Itīs nothing new or special, just some basic stuff,
but it covers some FAQs in the help-section of the forum.
I made some functions (just below), you can use in your own scripts
and some little tools:
A Click-Recorder/Script-Writer to record mouseclicks into ahk-scripts.
A SendMode/KeyDelay-Tester to quickly test different SendModes and KeyDelays with your own mouse-clicking and key-pressing hotkey or subroutine.
The folowing 7 functions are all independend of each other,
so you can copy only the needed ones:
There are two functions to let the user select a position or area on the screen.
definescreenarea
definescreenposition
There are four functions to randomly click/right-click in a certain screen-area.
randomclick
randomclickinarea
randomrightclick
randomrightclickinarea
The last function sleeps for a random time
| Code: |
; definescreenarea(varprefix) will promt the user to define an area on the screen via the
; Top-Left and Bottom-Right Position.
; the function will create 4 vars containing the X and Y coordinates of the Top-Left and Bottom-Right Position
; the vars are named: [varprefix]Xtopleft , [varprefix]Ytopleft , [varprefix]Xbottomright , [varprefix]Ybottomright
; example: " definescreenarea("myprefix") ".
; This will create the vars myprefixXtopleft , myprefixYtopleft ,and so on
; if no varprefix is given, the defaultprefix "area" is used
; example: " definescreenarea() ".
; This will create the vars areaXtopleft , areaYtopleft ,and so on
definescreenarea(varprefix = "area")
{
global
local xtopleft, ytopleft, xbottomright, ybottomright, mbuttonstate
ToolTip, Define screen area `n from Top-Left to Bottom-Right, , , 20
loop
{
MouseGetPos, xtopleft, ytopleft
Tooltip, Click to select the Top-Left position of the area`nX:%xtopleft% Y:%ytopleft%, , , 20
GetKeyState, mbuttonstate, LButton
if mbuttonstate = D
break
}
Tooltip, Top-Left position selected`nX:%xtopleft% Y:%ytopleft%, , , 20
KeyWait, LButton
loop
{
MouseGetPos, xbottomright, ybottomright
Tooltip, Click to select the Bottom-Right position of the area`nX:%xbottomright% Y:%ybottomright%, , , 20
GetKeyState, mbuttonstate, LButton
if mbuttonstate = D
break
}
Tooltip, Bottom-Right position selected`nX:%xbottomright% Y:%ybottomright%, , , 20
KeyWait, LButton
Tooltip, Area selected, , , 20
%varprefix%Xtopleft := xtopleft
%varprefix%Ytopleft := ytopleft
%varprefix%Xbottomright := xbottomright
%varprefix%Ybottomright := ybottomright
Tooltip, , , , 20
}
; definescreenposition(varprefix) will promt the user to define a position on the screen
; the function will create 2 vars containing the X and Y coordinates of this Position
; the vars are named: [varprefix]Xpos , [varprefix]Ypos
; example: " definescreenposition("myprefix") ".
; This will create the vars myprefixXpos , myprefixYpos
; if no varprefix is given, the defaultprefix "position" is used
; example: " definescreenposition() ".
; This will create the vars positionXpos , positionYpos
definescreenposition(varprefix = "position")
{
global
local xpos, ypos, mbuttonstate
ToolTip, Define screen position, , , 20
loop
{
MouseGetPos, xpos, ypos
Tooltip, Click to select the Position`nX:%xpos% Y:%ypos%, , , 20
GetKeyState, mbuttonstate, LButton
if mbuttonstate = D
break
}
Tooltip, Position selected`nX:%xpos% Y:%ypos%, , , 20
KeyWait, LButton
Tooltip, Area selected, , , 20
%varprefix%Xpos := xpos
%varprefix%Ypos := ypos
Tooltip, , , , 20
}
;--------------------------------------
; randomclick(Xcoord, Ycoord, offset, mode) will click on a random point in the area
; between [X/Ycoord-offset] and [X/Ycoord+offset]
; you can use different send-modes through the mode-var:
; mode = 0 : default send mode
; mode = 1 : using send mode Event
; mode = 2 : using send mode Input
; mode = 3 : using send mode Play
; if no mode is given, the default send mode is used
; example: "randomclick(100, 200, 10)". This will click on a random position
; between x=90 & x=110 and y=190 & y=210
randomclick(xcoord, ycoord, offset = 0, mode = 0)
{
Random, randx, -%offset%, %offset%
Random, randy, -%offset%, %offset%
xcoord += %randx%
ycoord += %randy%
if (mode != 0)
{
if (mode = 1)
SendMode Event
if (mode = 2)
SendMode Input
if (mode = 3)
SendMode Play
}
Click %xcoord%, %ycoord%
if (mode != 0)
SendMode Event
}
; randomclickinarea(xtopleft, ytopleft, xbottomright, ybottomright, mode) will click on a random point in the area
; between [X/Ytopleft] and [X/Ybottomright]
; you can use different send-modes through the mode-var:
; mode = 0 : default send mode
; mode = 1 : using send mode Event
; mode = 2 : using send mode Input
; mode = 3 : using send mode Play
; if no mode is given, the default send mode is used
; example: "randomclickinarea(100, 300, 200, 400)". This will click on a random position
; between x=100 & x=200 and y=300 & y=400
randomclickinarea(xtopleft, ytopleft, xbottomright, ybottomright, mode = 0)
{
Random, xcoord, %xtopleft%, %xbottomright%
Random, ycoord, %ytopleft%, %ybottomright%
if (mode != 0)
{
if (mode = 1)
SendMode Event
if (mode = 2)
SendMode Input
if (mode = 3)
SendMode Play
}
Click %xcoord%, %ycoord%
if (mode != 0)
SendMode Event
}
; randomrightclick(Xcoord, Ycoord, offset, mode) will click the right mouse-button on a
; random point in the area between [X/Ycoord-offset] and [X/Ycoord+offset]
; you can use different send-modes through the mode-var
; example: "randomrightclick(100, 200, 10)". This will click the right mouse-buttonon a random position
; between x=90 & x=110 and y=190 & y=210
randomrightclick(xcoord, ycoord, offset = 0, mode = 0)
{
Random, randx, -%offset%, %offset%
Random, randy, -%offset%, %offset%
xcoord += %randx%
ycoord += %randy%
if (mode != 0)
{
if (mode = 1)
SendMode Event
if (mode = 2)
SendMode Input
if (mode = 3)
SendMode Play
}
Click right %xcoord%, %ycoord%
if (mode != 0)
SendMode Event
}
; randomrightclickinarea(xtopleft, ytopleft, xbottomright, ybottomright, mode) will click the right mouse-button on a
; random point in the area between [X/Ytopleft] and [X/Ybottomright]
; you can use different send-modes through the mode-var
; example: "randomrightclickinarea(100, 300, 200, 400)". This will click the right mouse-button on a random position
; between x=100 & x=200 and y=300 & y=400
randomrightclickinarea(xtopleft, ytopleft, xbottomright, ybottomright, mode = 0)
{
Random, xcoord, %xtopleft%, %xbottomright%
Random, ycoord, %ytopleft%, %ybottomright%
if (mode != 0)
{
if (mode = 1)
SendMode Event
if (mode = 2)
SendMode Input
if (mode = 3)
SendMode Play
}
Click right %xcoord%, %ycoord%
if (mode != 0)
SendMode Event
}
;--------------------------------------
; randomsleep(sleeptime, offset) halts the script for a random time
; between [sleeptime-offset] and [sleeptime+offset] in milliseconds
; example: "randomsleep(2000, 1000)". This will halt the script for a random time between 1 and 3 seconds
randomsleep(sleeptime = 1000, offset = 200)
{
Random, randtime, -%offset%, %offset%
sleeptime += %randtime%
Sleep, %sleeptime%
} |
Attention: these are only functions, you need to incorporate them in your own script to get any result
check out the functions in the following posts, too ...
Keywords:
auto-mine , auto-click , auto-buy , automine , autoclick , autobuy , click , drag , randomly , random-click , random-sleep , random , auto , click , mouse , move , game , browsergame, automation , drag and drop , click-recorder , record , script-writer , script , writer _________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there...
Last edited by Zed Gecko on Sun Jun 01, 2008 8:42 am; edited 7 times in total |
|
| Back to top |
|
 |
BoBoĻ Guest
|
Posted: Fri Jul 06, 2007 9:41 am Post subject: |
|
|
Thx for your effort & sharing this. Would you mind to finaly add a WriteMeAScript() function  |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Fri Jul 06, 2007 5:46 pm Post subject: |
|
|
^^
Roger, iīm trying really hard, but
i still have some trouble with the FindOutWhatTheUserReallyWants() function  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Sat Jul 07, 2007 2:44 pm Post subject: |
|
|
very cool,
i think DWIM(x) is so essential,
Chris should introduce this to autohotkey as soon as possible.
I canīt live without it anymore  |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Sat Jul 07, 2007 3:05 pm Post subject: |
|
|
I also have some functions for stealthy game macroing, here are two of them:
| Code: | Click(x, y, p = "", e = 5) {
Random, r, 5, 30
SetDefaultMouseSpeed, r
Random, r, -e, e
x += r
Random, r, -e, e
y += r
Click %p% %x% %y%
Sleep, 10
}
Sleep(d, e = 0.4) {
Random, r, d * (1 - e), d * (1 + e)
Sleep, r
} |
_________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Zed Gecko
Joined: 23 Sep 2006 Posts: 98
|
Posted: Wed Jul 11, 2007 6:39 am Post subject: |
|
|
similar to the randomclick()-function i made the
randomclickdrag()-function
| Code: | ; randomclickdrag(xcoord1, ycoord1, xcoord2, ycoord2, speed, offset, mode)
; will leftclick-drag from a random point around x/ycoord1 to a random point around x/ycoord2
; speed = the speed to move the mouse in the range 0 (fastest) to 100 (slowest)
; you can use different send-modes through the mode-var:
; mode = 0 : default send mode
; mode = 1 : using send mode Event
; mode = 2 : using send mode Input
; mode = 3 : using send mode Play
; if no mode is given, the default send mode is used
; example: randomclickdrag(100, 100, 200, 200, 10, 5)
randomclickdrag(xcoord1, ycoord1, xcoord2, ycoord2, speed = 2, offset = 0, mode = 0)
{
Random, randx, -%offset%, %offset%
Random, randy, -%offset%, %offset%
xcoord1 += %randx%
ycoord1 += %randy%
Random, randx, -%offset%, %offset%
Random, randy, -%offset%, %offset%
xcoord2 += %randx%
ycoord2 += %randy%
if (mode != 0)
{
if (mode = 1)
SendMode Event
if (mode = 2)
SendMode Input
if (mode = 3)
SendMode Play
}
MouseClickDrag, L, %xcoord1%, %ycoord1%, %xcoord2%, %ycoord2% , %speed%
Click %xcoord%, %ycoord%
if (mode != 0)
SendMode Event
}
|
|
|
| Back to top |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1157 Location: Enterprise, Alabama
|
Posted: Wed Aug 01, 2007 7:49 pm Post subject: |
|
|
I've also made some functions. dieomclick() dieomsleep()
| Code: | ; dieomclick
; Example dieomclick(100, 100, 10) Clicks X90-110 Y90-110
dieomclick(xcoord, ycoord, offset = 0)
{
Random, diex, -%offset%, %offset%
Random, diey, -%offset%, %offset%
xcoord += %diex%
ycoord += %diey%
Click, Left, %xcoord%, %ycoord%
} |
| Code: | ; dieomsleep
; example dieomsleep(1000, 100) Waits 900-1100 Milliseconds
dieomsleep(sleep, rsleep = 0)
{
Random, dies, -%rsleept%, %rsleep%
sleep += %dies%
Sleep, %sleep%
} |
_________________ ScriptPad/~dieom/dieom/izwian2k7/Trikster/God
 |
|
| Back to top |
|
 |
Zed Gecko
Joined: 23 Sep 2006 Posts: 98
|
Posted: Sat May 31, 2008 10:12 pm Post subject: Simple Click-Recorder |
|
|
I made a little Click-Recorder,
it records Left/Middle/Right-MouseClicks and displays them as an ahk-script, so you can include them in your scripts.
The functionality is limited:
you can record MouseClicks,
and you can change the CoordMode for clicks from relative to screen and back.
Usage: after the script is started, it shows a MsgBox which tells you all usable hotkeys:
Press "Pause" to start/stop the click-recording.
Press "Escape" to show/update the GUI!
Press "Ctrl+Alt+M" to toggle the CoordMode.
Press "Ctrl+Alt+T" enable/disable a Tooltip showing your last action.
| Code: | ;Simple Click Recorder Script
; This Script will record Left/Middle/Right Mouseclicks to be used as an ahk-script itself!
;Start of the autoexecution-section
#InstallMouseHook
SetBatchLines -1
Suspend, On
PrevTime = 0
TTMode = off
HelpMessage =
(
Press "Pause" to start/stop the click-recording.
Press "Escape" to show/update the GUI!
Press "Ctrl+Alt+M" to toggle the CoordMode.
Press "Ctrl+Alt+T" enable/disable a Tooltip showing your last action.
)
CurrCoordMode = relative
ScriptVar .= "CoordMode`, Mouse `, relative" . "`n"
CoordMode, Mouse , relative
Gui, Add, Text, w350, %HelpMessage%
Gui, Add, Text, w350 Center Cwhite, Your Script so far:
Gui, Add, Edit, w350 r35 vScriptDisplay
Gui, Add, Button, gCopytoClip, Copy to Clipboard
Gui, Add, Button, x+20 gClearScript, Clear Script
MsgBox, %HelpMessage%
;End of the autoexecution-section
return
;Hotkey to Show/Refresh the Gui that displays the created script
Esc::
Suspend, Permit
GuiControl, , ScriptDisplay, %ScriptVar%
Gui,Show, ,Simple AHK-Script Recorder
return
;Hotkey to enable/disable the click-recording Hotkeys
Pause::
Suspend
if A_IsSuspended = 1
LastLine = Click Recording: OFF
else
LastLine = Click Recrding: ON
Gosub, affirmate
return
;Hotkey to Toggle the showing of affirmation-tooltips
^!T::
Suspend, Permit
if TTMode = on
TTMode = off
else
TTMode = on
LastLine := "ToolTip: Mode: " . TTMode
Gosub, affirmate
return
;the show tooltip subrutines
affirmate:
if TTMode = on
{
ToolTip, %LastLine%
SetTimer, RemoveToolTip, 1000
}
GuiControl, , ScriptDisplay, %ScriptVar%
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
;Hotkey to change the CoordMode of recording AND recorded script
!^M::
Suspend, Permit
if CurrCoordMode = relative
{
CoordMode, Mouse , screen
CurrCoordMode = screen
ScriptVar .= "CoordMode`, Mouse `, screen" . "`n"
LastLine := "CoordMode`, Mouse `, screen" . "`n"
}
else
{
CoordMode, Mouse , relative
CurrCoordMode = relative
ScriptVar .= "CoordMode`, Mouse `, relative" . "`n"
LastLine := "CoordMode`, Mouse `, relative" . "`n"
}
Gosub, affirmate
return
;Simple Click recording hotkeys for Left/Middle/Right-click
~LButton::
MouseGetPos, CurrPosX, CurrPosY
CurrTime := A_TickCount
if PrevTime > 1
{
ElapsedTime := CurrTime - PrevTime
ScriptVar .= "Sleep`, " . ElapsedTime . "`n"
}
ScriptVar .= "Click " . CurrPosX . "`, " . CurrPosY . "`n"
LastLine := "Click " . CurrPosX . "`, " . CurrPosY . "`n"
PrevTime := CurrTime
Gosub, affirmate
return
~RButton::
MouseGetPos, CurrPosX, CurrPosY
CurrTime := A_TickCount
if PrevTime > 1
{
ElapsedTime := CurrTime - PrevTime
ScriptVar .= "Sleep`, " . ElapsedTime . "`n"
}
ScriptVar .= "Click right " . CurrPosX . "`, " . CurrPosY . "`n"
LastLine := "Click right " . CurrPosX . "`, " . CurrPosY . "`n"
PrevTime := CurrTime
Gosub, affirmate
return
~MButton::
MouseGetPos, CurrPosX, CurrPosY
CurrTime := A_TickCount
if PrevTime > 1
{
ElapsedTime := CurrTime - PrevTime
ScriptVar .= "Sleep`, " . ElapsedTime . "`n"
}
ScriptVar .= "Click middle " . CurrPosX . "`, " . CurrPosY . "`n"
LastLine := "Click middle " . CurrPosX . "`, " . CurrPosY . "`n"
PrevTime := CurrTime
Gosub, affirmate
return
; Gui Handling Subroutines
CopytoClip:
Gui, Submit, Nohide
Clipboard := ScriptDisplay
MsgBox, Script copied to Clipboard
return
ClearScript:
ScriptVar =
CurrCoordMode = relative
ScriptVar .= "CoordMode`, Mouse `, relative" . "`n"
CoordMode, Mouse , relative
GuiControl, , ScriptDisplay, %ScriptVar%
return |
_________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there... |
|
| Back to top |
|
 |
Zed Gecko
Joined: 23 Sep 2006 Posts: 98
|
Posted: Sun Jun 01, 2008 8:27 am Post subject: Script to quickly test different SendModes and KeyDelays |
|
|
This is a Script to quickly test different SendModes and KeyDelays with your own mouse-clicking and key-pressing hotkey or subroutine.
If you were ever pointed to this link: http://www.autohotkey.com/docs/FAQ.htm#games, you might want to try out different SendModes and KeyDelays within your own script. And you might wonder if it is possible without changing the script for each variant you want to try.
With the following little script can easily try out massive amounts of variants with one-hotkey.
Simply put the folowing script at the bottom of your script (without the demo-part) and put the lable "testcase:" in the line over your hotkey definition. Run it, press Ctrl+Alt+X to start testing. A MessageBx will apear after each test, asking you, if it worked.
If so, press the "Yes"-Button and you will see the timing-details and the SendMode.
If not, do nothing or hit "No", the test will go on:
| Code: |
; SendMode/KeyDelay Tester
;--------------------------------------------------------
; please note: this is not a full script
; it is a script-pice you can insert in your own script
; to test different Settings for mouse-clicks
;--------------------------------------------------------
; Usage:
; enter the lable "testcase:" in the line over your hotkey definition:
; e.g. change this:
; ^!T::
; Mouseclick, left, 100, 100
; return
; to this:
; testcase:
; ^!T::
; Mouseclick, left, 100, 100
; return
;
; then paste the folowing script
; at the bottom of your script
^!x:: ; start the testing with Ctrl+Alt+X (make shure no other Ctrl+Alt+X-Hotkey exist)
; edit the values below to explore bigger or smaller timing-scopes
KeyDelayStart = 0
KeyDelayEnd = 100
PressDurationStart = 0
PressDurationEnd = 100
Granularity = 10
WinGet, active_id, ID, A
;---------start the testing-------
SendMode Event
SendModeVar = Event
TempKeyDelay := KeyDelayStart
loop
{
TempPressDuration := PressDurationStart
loop
{
SetKeyDelay , %TempKeyDelay%, %TempPressDuration%
WinActivate, ahk_id %active_id%
sleep, 100
Gosub, testcase
sleep, 100
MsgBox, 4, Test-Case, Did it work?, 3
IfMsgBox Yes
{
MsgBox KeyDelay :%TempKeyDelay% `nPressDuration :%TempPressDuration% `nSendmode : Event
return
}
if ( TempPressDuration >= PressDurationEnd )
break
TempPressDuration += Granularity
}
if ( TempKeyDelay >= KeyDelayEnd )
break
TempKeyDelay += Granularity
}
SendMode Play
SendModeVar = Play
TempKeyDelay := KeyDelayStart
SetKeyDelay , -1, -1, play
WinActivate, ahk_id %active_id%
sleep, 100
Gosub, testcase
sleep, 100
MsgBox, 4, Test-Case, Did it work?, 3
IfMsgBox Yes
{
MsgBox KeyDelay :-1 `nPressDuration :-1 `nSendmode : Play
return
}
loop
{
TempPressDuration := PressDurationStart
loop
{
SetKeyDelay , %TempKeyDelay%, %TempPressDuration%, play
WinActivate, ahk_id %active_id%
sleep, 100
Gosub, testcase
sleep, 100
MsgBox, 4, Test-Case, Did it work?, 3
IfMsgBox Yes
{
MsgBox KeyDelay :%TempKeyDelay% `nPressDuration :%TempPressDuration% `nSendmode : Play
return
}
if ( TempPressDuration >= PressDurationEnd )
break
TempPressDuration += Granularity
}
if ( TempKeyDelay >= KeyDelayEnd )
break
TempKeyDelay += Granularity
}
SendMode Input
SendModeVar = Input
TempKeyDelay := KeyDelayStart
loop
{
TempPressDuration := PressDurationStart
loop
{
SetKeyDelay , %TempKeyDelay%, %TempPressDuration%
WinActivate, ahk_id %active_id%
sleep, 100
Gosub, testcase
sleep, 100
MsgBox, 4, Test-Case, Did it work?, 3
IfMsgBox Yes
{
MsgBox KeyDelay :%TempKeyDelay% `nPressDuration :%TempPressDuration% `nSendmode : Input
return
}
if ( TempPressDuration >= PressDurationEnd )
break
TempPressDuration += Granularity
}
if ( TempKeyDelay >= KeyDelayEnd )
break
TempKeyDelay += Granularity
}
MsgBox Nothing worked so far. `n Try out "ControlSend", it maybe helps!
return
;--------------------------------------------------------
;demo testcase for testing the test-script ;-)
; DO NOT copy this to your script!!!!
testcase:
^!T::
Mouseclick, left, 100, 100
return |
Keywords: www.autohotkey.com/docs/FAQ.htm#games , Why do Hotstrings, Send, and Click have no effect in certain games? DirectInput , SetKeyDelay , SendMode , Input , Play , Event , InputThenPlay , Delay, PressDuration _________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there... |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|