Vas wrote:
... seem i'm missing some basic education in regards to AHK.
If i keep If WinActive("ahk_exe winword.exe") it works perfectly, but if i add one "space" before the brakets, the code stop working propertly.
... adn if you point me to where can i lear the slight syntax quirks, that'll be great.
When using command(MsgBox, WinActivate ...), default type of input is mostly traditional (not expression)
but when it comes to function, type is expression
Which means...
Code: Select all
; variable name 'Variable' is storing number 100
; = variable name 'Variable' is referencing number 100
Variable := 100
; it's not 100, but string(text) "Variable"
; Because 'MsgBox' is a command, hence only takes argument as a traditinal type
Msgbox, Variable
; So, in order to pass a variable properly, we need change the current type(= traditional) to expression
; To force expression, enclose variable with percent signs, or like % variable
; then it forces AutoHotkey to interpret a reference(100) of a variable, rather than the text of it("Variable")
MsgBox, % Variable
; However, this is 100, why ?
; Because MsgBoxFunction is a function, meaning it takes arguments(= parameters) as a expression type
; so the reference of variable name 'Variable' is passed (100)
MsgBoxFunction(Variable)
; In expression type, to express a string("Variable") rather than a reference
; enclose a string with double quotes, (e.g "Variable")
MsgBoxFunction("Variable")
MsgBoxFunction(Text)
{
MsgBox, % Text
}
Now, let's see your code again
It's okay, IfWinExist is a command and 'ahk_exe winword.exe' is a string text, not a reference of something
Syntax is wrong. WinActive is an native function of ahk, and it's correct syntax is WinActive("WinTitle")
so it should be WinActive("ahk_exe winword.exe")
or if you assign a variable that refers to "ahk_exe winword.exe", code should be like
Code: Select all
var := "ahk_exe winword.exe"
WinActive(var)
okay, WinActivate is a command
Code: Select all
Run, "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk"
Not okay, Run is a command, hence ...
Code: Select all
Run, C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk
or
file := "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk"
Run, % file
and finally
If i keep If WinActive("ahk_exe winword.exe") it works perfectly, but if i add one "space" before the brakets, the code stop working propertly.
Because "ahk_exe winword.exe" (without a space) and "ahk_exe winword.exe " (with a space) is a different string
WinActive("ahk_exe winword.exe") checks for Window title name ahk_exe winword.exe
while WinActive("ahk_exe winword.exe ") checks ahk_exe winword.exe (with a space after)