Tyrus Posted February 28, 2023 Share Posted February 28, 2023 I've been trying to create the most human like mouse movement script possible with multiple characteristics but I'm having trouble The script can be ran with parameters via the command line, but the script always throws "unknown function name" no matter what.. I figured I was missing imports, so I added them, and yet the issue always seems to remain. What am I doing wrong here? expandcollapse popup#include <Math.au3> #include <WinAPI.au3> ; Random seed RandomSeed(@MilliSeconds) ; Define movement characteristics Global $max_speed = 100 ; Maximum cursor speed Global $min_speed = 10 ; Minimum cursor speed Global $max_accel = 10 ; Maximum cursor acceleration Global $min_accel = 2 ; Minimum cursor acceleration Global $max_jerk = 10 ; Maximum cursor jerk Global $min_jerk = 2 ; Minimum cursor jerk Global $max_pause = 2000 ; Maximum pause time (in milliseconds) Global $min_pause = 100 ; Minimum pause time (in milliseconds) ; Check command line arguments If $CmdLine[0] <> 3 Then ConsoleWrite("Usage: " & @ScriptName & " x y duration" & @CRLF) Exit EndIf ; Parse command line arguments Global $x = $CmdLine[1] Global $y = $CmdLine[2] Global $duration = $CmdLine[3] ; Call the MouseMovement function MouseMovement($x, $y, $duration) Func MouseMovement($x, $y, $duration) ; Calculate movement parameters $distance = Sqrt(($x - MouseGetPos(0)) ^ 2 + ($y - MouseGetPos(1)) ^ 2) $speed = Random($min_speed, $max_speed) $accel = Random($min_accel, $max_accel) $jerk = Random($min_jerk, $max_jerk) ; Move the cursor in a random curve $t = 0 While $t <= $duration ; Calculate new cursor position $pos_x = MouseGetPos(0) + $speed * Cos($t) * Sign($x - MouseGetPos(0)) $pos_y = MouseGetPos(1) + $speed * Sin($t) * Sign($y - MouseGetPos(1)) ; Move the cursor to the new position _WinAPI_SetCursorPos($pos_x, $pos_y) ; Add random perturbations to the cursor movement $pos_x += Random(-$jerk, $jerk) $pos_y += Random(-$jerk, $jerk) _WinAPI_SetCursorPos($pos_x, $pos_y) ; Wait for a short pause Sleep(Random($min_pause, $max_pause)) ; Update time $t += $speed / $distance WEnd ; Move the cursor to the final position _WinAPI_SetCursorPos($x, $y) EndFunc Link to comment Share on other sites More sharing options...
Nine Posted February 28, 2023 Share Posted February 28, 2023 (edited) Have you tried running it from Scite ? Of course you would need to replace command line parameters with static numbers. I am telling you that because it is the first step in debugging a script. Here is a hint : SRandom. Edited February 28, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Tyrus Posted February 28, 2023 Author Share Posted February 28, 2023 1 minute ago, Nine said: Have you tried running it from Scite ? Of course you would need to replace command line parameters with static numbers. I am telling you that because it is the first step in debugging a script. Here is a hint : SRandom. I appreciate your response, I only use scite, but yeah it just says "unknown function name" every time I compile it and run it hmm.... Link to comment Share on other sites More sharing options...
Musashi Posted February 28, 2023 Share Posted February 28, 2023 29 minutes ago, Nine said: Have you tried running it from Scite ? Of course you would need to replace command line parameters with static numbers. Not necessarily. Within SciTE you can open a window using SHIFT F8. There you can enter command line parameters (even several in one line). This is helpful during development. The parameters set are preserved during the SciTE session. Nine and pixelsearch 1 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Nisteo Posted February 28, 2023 Share Posted February 28, 2023 2 hours ago, Tyrus said: What am I doing wrong here? I see 2 undefined functions and 1 wrong macro Link to comment Share on other sites More sharing options...
Developers Jos Posted February 28, 2023 Developers Share Posted February 28, 2023 5 hours ago, Tyrus said: I've been trying to create the most human like mouse movement script possible with multiple characteristics but I'm having trouble ...and the purpose of this script is? - game? - fool my boss. - other? What exactly? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Tyrus Posted February 28, 2023 Author Share Posted February 28, 2023 9 hours ago, Jos said: ...and the purpose of this script is? - game? - fool my boss. - other? What exactly? Simply just a class project we are allowed to approach in any way we want, so I thought I'd give this a go in AutoIt Link to comment Share on other sites More sharing options...
Tyrus Posted February 28, 2023 Author Share Posted February 28, 2023 12 hours ago, Nisteo said: I see 2 undefined functions and 1 wrong macro Tried giving it another go but still failed miserably, dang this sucks Link to comment Share on other sites More sharing options...
Nine Posted March 1, 2023 Share Posted March 1, 2023 4 minutes ago, Tyrus said: dang this sucks Wonder what sucks in here. Did you even try to run it with Scite ? Show me a print screen of Scite result and now tell what you do not understand. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mistersquirrle Posted March 1, 2023 Share Posted March 1, 2023 I'm curious, did you try to get some AI to write this? I can get ChatGPT to write something pretty similar, but there's some very strange things in your script that make me think you didn't write it. I don't think that there's anything against the rules of the forum with using AI to generate something, though you should probably mention it. It seems like you're pretty unfamiliar with AutoIt or still new to it. If that's the case, using an AI to generate a script is not a good idea, since you have no idea why what it generated is wrong and doesn't work If you want to learn a bit more about making more 'human' movement, check out something like https://ben.land/post/2021/04/25/windmouse-human-mouse-movement/. I don't see why you couldn't convert something like this into AutoIt, and there's probably already someone that has. Here's some similar things: We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Tyrus Posted March 1, 2023 Author Share Posted March 1, 2023 11 minutes ago, mistersquirrle said: I'm curious, did you try to get some AI to write this? I can get ChatGPT to write something pretty similar, but there's some very strange things in your script that make me think you didn't write it. I don't think that there's anything against the rules of the forum with using AI to generate something, though you should probably mention it. It seems like you're pretty unfamiliar with AutoIt or still new to it. If that's the case, using an AI to generate a script is not a good idea, since you have no idea why what it generated is wrong and doesn't work If you want to learn a bit more about making more 'human' movement, check out something like https://ben.land/post/2021/04/25/windmouse-human-mouse-movement/. I don't see why you couldn't convert something like this into AutoIt, and there's probably already someone that has. Here's some similar things: I took a lot of snippets doing research on it I didn't write most of it, but I am trying to understand it It's just the error it's giving me doesn't help me I'm struggling to understand what it actually means, since the line number it's giving me doesn't even exist lol Link to comment Share on other sites More sharing options...
mistersquirrle Posted March 1, 2023 Share Posted March 1, 2023 2 minutes ago, Tyrus said: It's just the error it's giving me doesn't help me I'm struggling to understand what it actually means, since the line number it's giving me doesn't even exist lol 1 hour ago, Nine said: Wonder what sucks in here. Did you even try to run it with Scite ? Show me a print screen of Scite result and now tell what you do not understand. How about you do what Nine is asking, and also if you still have it, links to where you'd grabbed snippets. Seems like you didn't grab everything you need. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Tyrus Posted March 1, 2023 Author Share Posted March 1, 2023 (edited) 7 minutes ago, mistersquirrle said: How about you do what Nine is asking, and also if you still have it, links to where you'd grabbed snippets. Seems like you didn't grab everything you need. Seems to be the RandomSeed function causing the issue, but I imported math so I don't understand why it's not working.. Human_Mouse.au3" (6) : ==> Unknown function name.: RandomSeed(@MilliSeconds) ^ ERROR >Exit code: 1 Sorry forgot to include this:https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/Lua/manual.html I had added the random seed after reading about it in the math function: math.randomseed Edited March 1, 2023 by Tyrus Link to comment Share on other sites More sharing options...
mistersquirrle Posted March 1, 2023 Share Posted March 1, 2023 Keep in mind that what you've referenced is NOT AutoIt, it's its editor, SciTE, which uses LUA: http://lua-users.org/wiki/MathLibraryTutorial For AutoIt, the main Random function is Random, also I don't know what you're trying to do with RandomSeed. You don't get any output from it, and why would you need to change a seed? Here's AutoIt Randoms function: https://www.autoitscript.com/autoit3/docs/functions/Random.htm Also the Math.au3 file that you've included only has a couple of functions: https://www.autoitscript.com/autoit3/docs/libfunctions/Math Management.htm And for the output, the line that has an error is 6: RandomSeed(@MilliSeconds) @MilliSeconds is also not a valid macro: https://www.autoitscript.com/autoit3/docs/macros.htm In SciTE you can also do Ctrl + F5 to run a syntax/error checker, that should point you to a couple other problems. There's enough for you to ponder over for a little bit, see if you can get the script working or at least farther along. Tyrus 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Tyrus Posted March 1, 2023 Author Share Posted March 1, 2023 (edited) 5 minutes ago, mistersquirrle said: Keep in mind that what you've referenced is NOT AutoIt, it's its editor, SciTE, which uses LUA: http://lua-users.org/wiki/MathLibraryTutorial For AutoIt, the main Random function is Random, also I don't know what you're trying to do with RandomSeed. You don't get any output from it, and why would you need to change a seed? Here's AutoIt Randoms function: https://www.autoitscript.com/autoit3/docs/functions/Random.htm Also the Math.au3 file that you've included only has a couple of functions: https://www.autoitscript.com/autoit3/docs/libfunctions/Math Management.htm And for the output, the line that has an error is 6: RandomSeed(@MilliSeconds) @MilliSeconds is also not a valid macro: https://www.autoitscript.com/autoit3/docs/macros.htm In SciTE you can also do Ctrl + F5 to run a syntax/error checker, that should point you to a couple other problems. There's enough for you to ponder over for a little bit, see if you can get the script working or at least farther along. Appreciate that, ctrl+F5 should help me a fair bit, I'll get this figured out, thanks! Edited March 1, 2023 by Tyrus Link to comment Share on other sites More sharing options...
Trong Posted March 1, 2023 Share Posted March 1, 2023 (edited) I edited the code that I think was not written by you: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Random seed Global $Seed = 1000 SRandom($Seed) ;Set Seed for random number generation. Global $aTSR = _GetTotalScreenResolution() Global $DesktopWidth = $aTSR[0] Global $DesktopHeight = $aTSR[1] ; Define movement characteristics Global $max_speed = 100 ; Maximum cursor speed Global $min_speed = 10 ; Minimum cursor speed Global $max_accel = 10 ; Maximum cursor acceleration Global $min_accel = 2 ; Minimum cursor acceleration Global $max_jerk = 10 ; Maximum cursor jerk Global $min_jerk = 2 ; Minimum cursor jerk Global $max_pause = 2000 ; Maximum pause time (in milliseconds) Global $min_pause = 100 ; Minimum pause time (in milliseconds) Global $x, $y, $duration ; Check command line arguments If $CmdLine[0] > 2 Then ; Parse command line arguments $x = $CmdLine[1] $y = $CmdLine[2] $duration = $CmdLine[3] ; Call the MouseMovement function _MouseMovement($x, $y, $duration) Else ;~ _MouseMovement(100, 200, 10) ; Test ConsoleWrite("Usage: " & @ScriptName & " x y duration" & @CRLF) Exit EndIf Func _MouseMovement($x, $y, $duration) ; Calculate movement parameters $distance = Sqrt(($x - MouseGetPos(0)) ^ 2 + ($y - MouseGetPos(1)) ^ 2) $speed = _iRandom($min_speed, $max_speed) $accel = _iRandom($min_accel, $max_accel) $jerk = _iRandom($min_jerk, $max_jerk) ; Move the cursor in a random curve $t = 0 While $t <= $duration ; Calculate new cursor position $pos_x = MouseGetPos(0) + $speed * Cos($t) * Sin($x - MouseGetPos(0)) $pos_y = MouseGetPos(1) + $speed * Sin($t) * Sin($y - MouseGetPos(1)) ; Move the cursor to the new position _WinAPI_SetCursorPos($pos_x, $pos_y) ; Add random perturbations to the cursor movement $pos_x += _iRandom(-$jerk, $jerk) $pos_y += _iRandom(-$jerk, $jerk) _WinAPI_SetCursorPos($pos_x, $pos_y) ; Wait for a short pause Sleep(_iRandom($min_pause, $max_pause)) ; Update time $t += $speed / $distance WEnd ; Move the cursor to the final position _WinAPI_SetCursorPos($x, $y) EndFunc ;==>_MouseMovement Func _WinAPI_SetCursorPos($x, $y) If $x < 1 Then $x = 0 If $x > $DesktopHeight Then $x = $DesktopHeight If $y < 1 Then $y = 0 If $y < $DesktopWidth Then $y = $DesktopWidth DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y) If @error Then Return SetError(1, MouseMove($x, $y, $min_speed), 0) Return 1 EndFunc ;==>_WinAPI_SetCursorPos Func _iRandom($x, $y) Return Random($x, $y, 1) EndFunc ;==>_iRandom Func _GetTotalScreenResolution() Local $aRet[2] Global Const $SM_VIRTUALWIDTH = 78,$SM_VIRTUALHEIGHT = 79 $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH) If @error Then $aRet[0] = @DesktopWidth Else $aRet[0] = $VirtualDesktopWidth[0] EndIf $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT) If @error Then $aRet[1] = @DesktopHeight Else $aRet[1] = $VirtualDesktopHeight[0] EndIf Return $aRet EndFunc ;==>_GetTotalScreenResolution Edited March 2, 2023 by Trong I'm not good at math! Regards, Link to comment Share on other sites More sharing options...
mistersquirrle Posted March 1, 2023 Share Posted March 1, 2023 (edited) @Trong did you try running that code? It didn't work even remotely for me (even replacing your _WinAPI_SetCursorPos with just MouseMove), it mostly just kept the mouse at the bottom of the screen constantly (moving left/right). Also you've mixed up your @DesktopHeight/@DesktopWidth checks with $x/$y. Your checks in _WinAPI_SetCursorPos limits the usability to just the main monitor as well (at best, at worst it can completely jump the cursor to an undesired location, very un-"human" like). Edit: To be clear, I'm not trying to be mean or anything, the behavior of the cursor/script is mostly not related to what you updated. Using MouseMove instead of SetCursorPos just makes the cursor bounce around the screen without a care in the world about making it "human" like, or knowing what a straight line is. So I'll say this, this approach will not work for what you want to accomplish. Feel free to keep studying the structure of it, but the maths are not good. @Tyrus I again strongly recommend that you check out https://ben.land/post/2021/04/25/windmouse-human-mouse-movement/. I was able to convert this to AutoIt and it work very well for moving the cursor from point a -> b with some jitter and even overshoot and correction. I won't post the code for a couple reasons, but mainly that if this is for your class, it's probably best if you figure it out. Edited March 1, 2023 by mistersquirrle We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Tyrus Posted March 2, 2023 Author Share Posted March 2, 2023 13 hours ago, mistersquirrle said: @Trong did you try running that code? It didn't work even remotely for me (even replacing your _WinAPI_SetCursorPos with just MouseMove), it mostly just kept the mouse at the bottom of the screen constantly (moving left/right). Also you've mixed up your @DesktopHeight/@DesktopWidth checks with $x/$y. Your checks in _WinAPI_SetCursorPos limits the usability to just the main monitor as well (at best, at worst it can completely jump the cursor to an undesired location, very un-"human" like). Edit: To be clear, I'm not trying to be mean or anything, the behavior of the cursor/script is mostly not related to what you updated. Using MouseMove instead of SetCursorPos just makes the cursor bounce around the screen without a care in the world about making it "human" like, or knowing what a straight line is. So I'll say this, this approach will not work for what you want to accomplish. Feel free to keep studying the structure of it, but the maths are not good. @Tyrus I again strongly recommend that you check out https://ben.land/post/2021/04/25/windmouse-human-mouse-movement/. I was able to convert this to AutoIt and it work very well for moving the cursor from point a -> b with some jitter and even overshoot and correction. I won't post the code for a couple reasons, but mainly that if this is for your class, it's probably best if you figure it out. Yeah rather than help me it's best you make me do it on my own, cheers mate good job! Werty 1 Link to comment Share on other sites More sharing options...
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