用户在已编译的宏中更改变量

时间:2018-08-04 18:54:10

标签: macros autohotkey

我有一个变量,其值存储在AutoHotKey宏中。我希望用户将来可以随时更改变量,并让宏在将来启动宏时使用存储在变量中的新值。是否可以在正在运行的宏中更改变量,并让宏在下次启动宏时使用新的变量值?或者,用户是否可以更改已编译宏中的变量?我还想知道当用户选择更改变量时,用户界面如何能够更改变量?

1 个答案:

答案 0 :(得分:0)

当然,您可以将变量存储在文本文件中。这将是更改变量并将其永久存储的最简单,最可靠的方法。 这是一个例子。在同一目录中创建文件“ config.txt”,然后在其中放置文本。按下F1会将文本文件重新加载到变量v中。

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

fname := "config.txt"       ; define file name (must be in the same directory)
loadvar(fname)              ; load file
return                      ; end main 

; loadvar function
loadvar(fname){
    global v
    FileRead, v, %fname%
    tooltip %v%
}

; reload variable
F1::
    loadvar(fname)
return
相关问题