问题描述
global AssocArray := {}
Array := []
Loop,Read,links.txt
Array.Push(StrSplit(A_LoopReadLine,";"))
for index,element in Array {
browser := Func("Launch").Bind("chrome.exe --options ","firefox.exe -options ")
Menu,MyMenu,Add,% element.2,% browser
AssocArray[element.2] := element.3
}
Menu,Show
Launch(browserPC1,browserPC2,ItemName,ItemPos) {
browser := A_ComputerName = PC1 ? %browserPC1% : %browserPC2%
Run,% browser AssocArray[ItemName]
return
}
Format of links.txt:
;Arrays;https://autohotkey.com/docs/Arrays
如何在 Launch
中使用不同的浏览器,具体取决于我使用的是 PC1
还是 PC2
,以及我为不同菜单指定的浏览器(这就是为什么我没有简单地在 Launch
中指定它们?由于(我假设)破折号,我收到了非法字符错误。
解决方法
错误在这里:
Browser := A_ComputerName = PC1 ? %BrowserPC1% : %BrowserPC2%
您正在尝试使用动态变量。
在表达式语句中,您不会通过将变量包装在 %
中的传统 AHK 方式来引用变量。你只需简单地输入他们的名字,就像这样:
Browser := A_ComputerName = PC1 ? BrowserPC1 : BrowserPC2
还有一件事。变量 PC1
应该在哪里定义?
您是否想将其用作文字字符串 ("PC1"
)?