DigiBox Posted December 22, 2018 Posted December 22, 2018 (edited) Hello everyone, I decided to rewrite/convert some autohotkey scripts to autoit. I know Ahk pretty well, but I'm obviously new at autoit. I've done my best with this one and the problem I'm getting now is the error message "Error: Unknown function name". Forgive me if it's something simple, but like I said, I'm completely new at this (been at it for one day, while ahk for years). Here is the autoit script: expandcollapse popup#RequireAdmin If WinExists(@ScriptName) Then Exit AutoItWinSetTitle(@ScriptName) $slowness = IniRead ("extra.ini", "slownesss", slowness, "0") $slowdelay = IniRead ("extra.ini", "slownesss", slowdelay, "0") Global $Paused HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{DELETE}", "Terminate") $track = 0 while 1 global $pos2 = mousegetpos() Local $coord1 = PixelSearch (511, 388, 511, 424, 0xBD302E, 30) If Not @error Then exitloop EndIf wend For $redloop = 1 to 10 step 1 global $pos2 = mousegetpos() local $coord2 = PixelSearch (511, 388, 511, 424, 0xBD302E, 30) If Not @error Then $track = 1 EndIf If @error Then ExitLoop EndIf If $redloop > 0 Then $fade = $redloop / 100 EndIf $move = $slowness + fade if $track = 1 Then global $pos1 = mousegetpos() $newx1 = $pos1-$xpos2 $newx2 = $pos2-$xpos1 $movex = $newx2/move _MouseMovePlus($movex,0) global $pos2 = mousegetpos() $track = 0 EndIf Next while 1 sleep 1 local $coord3 = PixelSearch (511, 388, 511, 424, 0xBD302E, 30) If @error Then exitloop EndIf WEnd Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) WEnd EndFunc ; mousemove------------------------------------------ Func _MouseMovePlus($X, $Y,$absolute = 0) global $MOUSEEVENTF_MOVE = 1 Local $MOUSEEVENTF_ABSOLUTE = 32768 DllCall("user32.dll", "none", "mouse_event", _ "long", $MOUSEEVENTF_MOVE + ($absolute*$MOUSEEVENTF_ABSOLUTE), _ "long", $X, _ "long", $Y, _ "long", 0, _ "long", 0) EndFunc Func Terminate() Exit 0 EndFunc And here is the original Ahk script which I wrote (and works perfectly) : expandcollapse popup#SingleInstance force CoordMode, pixel,screen CoordMode, mouse,screen SetBatchLines -1 IniRead, slowness, extra.ini, slownesss, slowness IniRead, slowdelay, extra.ini, slownesss, slowdelay mouseXY(x,y) { DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0) } track = 0 loop { mousegetpos, xpos2, ypos2 PixelSearch, Px, Py, 511, 388, 511, 424, 0xBD302E, 30, fast RGB if errorlevel = 0 { sleep slowdelay gosub, red } } red: loop, 10 { mousegetpos, xpos2, ypos2 PixelSearch, Px, Py, 511, 388, 511, 424, 0xBD302E, 30, fast RGB if errorlevel = 0 track = 1 if errorlevel = 1 break if (a_index > 0) fade := (a_index / 100) move := (slowness + fade) if track = 1 { MouseGetPos, xpos1, ypos1 newx1 := (xpos1-xpos2) newx2 := (xpos2-xpos1) mousexy(newx2/move, 0) mousegetpos, xpos2, ypos2 track = 0 } } loop { sleep 1 PixelSearch, Px, Py, 511, 388, 511, 424, 0xBD302E, 30, fast RGB if errorlevel = 1 return } return Any help about the error is greatly appreciated and perhaps something else you may spot. Thanks in advance Edited December 22, 2018 by DigiBox typo
Danp2 Posted December 22, 2018 Posted December 22, 2018 15 minutes ago, DigiBox said: $slowness = IniRead ("extra.ini", "slownesss", slowness, "0") You need quotes around the 3rd parameter There are also other issues in your code. If you are using the full version of Scite, you can press Ctrl+F5 to perform a syntax check. P.S. Mind telling us what this script will be used for once it's working correctly? Latest Webdriver UDF Release Webdriver Wiki FAQs
DigiBox Posted December 22, 2018 Author Posted December 22, 2018 (edited) 18 minutes ago, Danp2 said: You need quotes around the 3rd parameter There are also other issues in your code. If you are using the full version of Scite, you can press Ctrl+F5 to perform a syntax check. P.S. Mind telling us what this script will be used for once it's working correctly? Thanks so much, that helped. Yes, I'm using Scite. I'll try to work out the other problems with the script using it. The script is used for making sort of an effect that slows down(/limits) the mouse movement sideways for a short while once the target color is found. If the target color is found and it goes away quickly then the function is canceled and it goes back to searching for the color. Once the script is working correctly the way to get it to react would be to have the red color appear in the center of the screen while you're moving the mouse quickly back and forth and you'll notice how it sort of sticks to where it is and gets harder to move for a short while (for the duration of the loop repeated 10 times. The number of times decides the duration of the slow-down). Then it waits for the red color to go away (errorlevel 1) before jumping back to the start of the script (first loop). Edited December 22, 2018 by DigiBox
Danp2 Posted December 22, 2018 Posted December 22, 2018 Be sure to read the Forum Rules, particularly the portion regarding game automation. What made you switch from AHK? Latest Webdriver UDF Release Webdriver Wiki FAQs
DigiBox Posted December 22, 2018 Author Posted December 22, 2018 It's not meant for any game. Sort of a way to automatically limit the mouse as opposed to using like a DPI shift button etc. I wanted to see in what ways it could be done. The color thing is just one creative way. It could be activated while holding a button etc also. I'm comparing the effectiveness of ahk and autoit.
DigiBox Posted December 22, 2018 Author Posted December 22, 2018 I got it working thanks to your advice on the syntax check Thanks and have a nice day! Xandy 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now