Autohotkey 使用自动热键对字符串进行编号

Autohotkey 使用自动热键对字符串进行编号,autohotkey,Autohotkey,我想让我的tail函数获取日志文件中的最后一行,并将其转换为一个数字。这样我就可以在if条件下使用它 file = C:\Users\%A_UserName%\Documents\logTime.txt Tail(k,file) ; Return the last k lines of file { Loop Read, %file% { i := Mod(A_Index,k) L%i% = %A_LoopReadLine% } L := L%

我想让我的tail函数获取日志文件中的最后一行,并将其转换为一个数字。这样我就可以在if条件下使用它

file = C:\Users\%A_UserName%\Documents\logTime.txt
Tail(k,file)   ; Return the last k lines of file
{
   Loop Read, %file%
   {
      i := Mod(A_Index,k)
      L%i% = %A_LoopReadLine%
   }
   L := L%i%
   Loop % k-1
   {
      IfLess i,1, SetEnv i,%k%
      i--      ; Mod does not work here
          L := L%i% "`n" L }
 ;Return L
 ;msgbox % Tail(1,file)
     }   
if条件

While (PrLoad > 5 ) ; Assign the Number you want. 
{
   If (Tail(1, file) = %A_Hour%%A_Min%)
   {
       msgBox is equal to Current Time  %Tail(1, file)%
       Sleep 60000

   }

Else if (Tail(1, file) > %A_Hour%%A_Min% )
{
    msgBox  Tail(1, file) is greater then %A_Hour%%A_Min%
    Sleep 60000
}
日志文件由以下人员生成:

FileAppend, %A_Hour%%A_Min%`n, C:\Users\%A_UserName%\Documents\logTime.txt
我确信我将函数错误地传递到if条件中。
%L%

如何将字符串转换为一个数字以供if语句比较?

您是否使用最新版本的AutoHotkey?如果没有,请从autohotkey.com或ahkscript.org下载最新版本

据我所见,您使用的是老式的伪数组

在此处阅读对象/阵列的当前状态:

我看到的主要问题是在变量周围错误地使用了%。函数不需要%%,命令需要%%


我希望您知道,
Tail(1,文件)>%A_Hour%%A_Min%
可能会导致意外结果

假设%A_Hour%%A_Min%为
1250
,Tail(1,文件)返回
0105

01:05可能在12:50之后发生,但您的脚本将无法看到这一点。
现在您可以继续添加日期、月份和年份,但这仍然不能消除所有问题

这就是为什么大多数人使用时间戳,它只表示自1970年以来经过的秒数

。。。 AHK可以像处理数字一样处理字符串,因此不会有任何问题。
尝试一下:

logFile = C:\Users\%A_UserName%\Documents\logTime.txt

;create a new timestamp and add it to the log
timestamp := GetUnixTimestamp()
FileAppend, %timestamp% `n, %logFile%

;wait a second
Sleep, 1000

;create another timestamp
currentTimestamp := GetUnixTimestamp()

;get old timestamp from log
timestampFromLog := FileGetLastLine(logFile)

MsgBox, %timestampFromLog% - Last timestamp from the log `n%currentTimestamp% - Current timestamp

If (currentTimestamp > timestampFromLog)
    MsgBox, Everything ran as expected!

GetUnixTimestamp() {
    T := A_NowUTC
    T -= 1970,s
    Return T
}

FileGetLastLine(file) {
    Loop, Read, %file%
        lineCount := A_Index

    FileReadLine, lastLine, %file%, %lineCount%
    Return lastLine
}

您的链接中有重复项。一个人应该去。