However, I would like to have the script behave differently now.
I want the script to detect a certain amount of time has passed without any changes made to a specific file. Once that amount of time has passed, then I would like the forward-slash "\" command to be sent.
My goal with this revision request is to cutdown on the number of "\" commands being sent.
For example, I want the script to send the "\" command if my specific txt file has not changed in 2 minutes.
If a change has been detected in 1:59 or less, then the script simply does nothing, and will continue to wait until the next update to the file occurs.
The script I have now is listed below.
Code: Select all
;=================================
;these 4 items are the only ones you need to modify to make this
; routine work. They should already be set up properly.
;------------------------------------------------------------
; this is the file path and file name of the file you want to check
; the timestamps on
filename = C:\file.txt
; this variable will let you check every second to see if the file
; has been modified. I don't recommend you set it lower than 500.
; go higher than 1000 if your game starts to lag from all the file checks.
sleeptime = 1000
; this is the name that appears on the top border of your game window
windowname = Team Fortress 2
; this is the background color of the script gui in RGB format (teal blue)
gui, color, 0x20f0f0
;=================================
;----------------------------------------------------------
; DO NOT MODIFY ANY CODE FROM THIS POINT ON
;----------------------------------------------------------
SetTitleMatchMode, 2
;This is a gui that will let you stop the loop when you're done
Gui, +Resize
Gui, Add, Text,, CheckFileTime
Gui, Add, Button, +E0x0101 w60, Quit
Gui, Show, , CheckFileTime
firstcall = 0
Gosub, CheckFileTime
loop
{
Gosub, CheckFileTime
Sleep, %sleeptime%
}
ButtonQuit:
GuiClose:
ExitApp
;---------------------------------------------------------
; this routine will automatically send the slash to the tf2 window
; when a diff in the timestamps is detected. It will also auto reset
; the marker time for the next comparison once the compare indicates
; that the file was changed.
;--------------------------------------------------------
; DO NOT MODIFY ANYTHING IN THIS ROUTINE
;--------------------------------------------------------
CheckFileTime:
; on a first call to this routine (when firstcall = 0) this routine will
; set up the initial marker timestamp
IfEqual, firstcall, 0
{
FileGetTime, FirstTimeStamp, %filename%, M
FirstCall = 1
return
}
; At this point the initial timestamp is available so we get the time
; stamp again to see if it's different from the marker
FileGetTime, CurrTimeStamp, %filename%, M
; if it's different than the marker...
IfNotEqual, CurrTimeStamp, %FirstTimeStamp%
{
;activate the tf2 window and send the \ key
WinActivate, %windowname%
Sleep, 100
Send, \
Sleep, 100
; since we have a difference and have sent the \ key we set up
; a new marker time
FirstCall = 0
Goto, CheckFileTime
}
Return
[Mod edit: Moved topic from AHK v2 help to v1 help, since this is v1 code.]