MoveMouse(X, Y, Speed=25) {
T := A_MouseDelay
SetMouseDelay, -1
MouseGetPos, CX, CY
Pts := Round(Sqrt((X - CX)**2 + (Y - CY)**2) / 30,0)
Loop %Pts% {
Random, NX, % CX - ((CX - X) / Pts) * (A_Index - 1)
, % CX - ((CX - X) / Pts) * A_Index
Random, NY, % CY - ((CY - Y) / Pts) * (A_Index - 1)
, % CY - ((CY - Y) / Pts) * A_Index
MouseMove, % NX, % NY, % Speed
}
MouseMove, % X, % Y, % Speed
SetMouseDelay, % T
}
Saturday, December 27, 2008
AHK - Random Mouse Path (MouseMove)
This functions chooses random points along the path from the current mouse position to the new one, and moves through those points on the way to the new position. This function is supposed to help prevent people from detecting the use of a bot based on movement patterns. The first two parameters are the X and Y coordinates respectively, and the third (optional) parameter is the speed at which the mouse will move. For more information on this parameter see here. The default is 25.
Tuesday, December 23, 2008
AHK - GenFile() - Generate files with exact size in bytes
This simple function will append exactly %Bytes% bytes to %Name%. This is useful for testing things that need to be able to move files, you can test for files of average size and get an accurate speed test.
GenFile(Name, Bytes) {
VarSetCapacity(FBytes, Bytes, 1)
FileAppend, % FBytes, % Name
}
GenFile("File.txt", 1024) ; Generates a 1kb file named "File.txt"
Labels:
AHK scripts,
Functions
Sunday, December 14, 2008
AHK - AlwaysOnTop Window Toggle
This script is great for use with script editors. For example, you need to look up detailed information about some commands, so you just hold down RAlt, look it up, then can switch back and forth simply by holding down RAlt again.
Forum Post
WinTitle = ahk_class Notepad
WinSet, AlwaysOnTop, On, % WinTitle
RAlt::
A := WinExist("A")
WinSet, AlwaysOnTop, Off, % WinTitle
WinActivate, % WinTitle
WinActivate, ahk_id %A%
Hotkey, RAlt, Off
Return
RAlt Up::
WinSet, AlwaysOnTop, On, % WinTitle
Hotkey, RAlt, On
Return
Forum Post
Sunday, December 7, 2008
AHK - RegEx - Return last X lines of text/text file
RegEx For returning last X lines of a piece of text (text lines should be delimited by just LF, files by CRLF). Replace red text with # of lines. First one is for plain text, second is for text files.
Forum Post
RegExReplace("^.*?((`n[^`n]*){#})$","$1")
RegExReplace(data,"^(.|`r)*?((`r`n[^`r`n]*){#}})$","$2")
Forum Post
AHK - UrlDownloadToFile Interruption
This first script is an example of how to pause UrlDownloadToFile, or simply to execute other functions while still downloading. The second is an example of how to pause the download, then exit the script and delete the download file without finishing it. Differences in the second code are highlighted in red.
Forum Post
Size = 300 ; approximate size in bytes of final file
SetTimer, CheckStatus, 10
;Download File
URLDownloadToFile, http://www.autohotkey.com/download/AutoHotkey104706_Install.exe, _tmp_AutoHotkey104706_Install.exe
Return
;Check Status
CheckStatus:
FileGetSize, FSize, _tmp_AutoHotkey104706_Install.exe
If (FSize >= Size) {
Critical ; Make so this thread can't interrupted
SetTimer, CheckStatus, off ; Stop checking status
FileRead, FileData, _tmp_AutoHotkey104706_Install.exe ; Read file
MsgBox % "Done!`n" (ErrorLevel ? "Error: " ErrorLevel : "`n" FileData) ; Done!
; Demonstrates interruption of UrlDownloadToFile
; Size of file stays the same
Loop, 1000 {
FileGetSize, FSize, _tmp_AutoHotkey104706_Install.exe
ToolTip, File Size (Paused): %FSize%
Sleep, 10
}
; Resume Download
SetTimer, CheckStatus2, 10
}
Return
CheckStatus2:
FileGetSize, FSize, _tmp_AutoHotkey104706_Install.exe
ToolTip, File Size (Resumed): %FSize%
Return
~Esc::
SetTimer, ExitApp, 10
Return
ExitApp:
ExitApp
Size = 300 ; approximate size in bytes of final file
OnExit, OnExit ; Execute "OnExit" label when exiting
SetTimer, CheckStatus, 10
;Download File
URLDownloadToFile, http://www.autohotkey.com/download/AutoHotkey104706_Install.exe, _tmp_AutoHotkey104706_Install.exe
Return
;Check Status
CheckStatus:
FileGetSize, FSize, _tmp_AutoHotkey104706_Install.exe
If (FSize >= Size) {
Critical
SetTimer, CheckStatus, off
FileRead, FileData, _tmp_AutoHotkey104706_Install.exe
ToolTip, File Size: %FSize%
MsgBox % "Done!`n" (ErrorLevel ? "Error: " ErrorLevel : "`n" FileData)
FileDelete, _tmp_AutoHotkey104706_Install.exe
; Demonstrates interruption of UrlDownloadToFile
; Size of file stays the same
Loop, 250 {
FileGetSize, FSize, _tmp_AutoHotkey104706_Install.exe
ToolTip, File Size (Paused): %FSize%
Sleep, 10
}
; Exit
ExitApp
}
Return
~Esc::
SetTimer, OnExit, 10
Return
OnExit:
; Create a batch file that will delete the download file and itself
FileAppend, ping http://www.google.com`nDel "%A_ScriptDir%\_tmp_AutoHotkey104706_Install.exe"`n Del "del.bat", del.bat
; Wait for file to exist
Loop {
If (FileExist("del.bat"))
break
}
; Run file
Run, del.bat, %A_ScriptDir%, HIDE
ExitApp
Forum Post
Subscribe to:
Posts (Atom)