Reputation: 570
I just want to compare two variables and check if they are equal. I have 2 commands for q and w that just set what the global lastCommand variable is. And for each command I want to do something if the lastCommand was a certain value but it doesn't seem to work. Is there something wrong with the way I'm trying to compare values in auto hot key?
#SingleInstance Force
CoordMode, Mouse, Client
CoordMode, Pixel, Client
SendMode Input
SetDefaultMouseSpeed, 0
global lastCommand := "q"
q::
if (lastCommand == "w") {
Msgbox last command was w
} else {
Msgbox % lastCommand
}
lastCommand = "q"
return
w::
if (lastCommand == "q") {
Msgbox last command was q
} else {
Msgbox % lastCommand
}
lastcommand = "w"
return
It's not complex...I just can't figure out why it's not working. The comparison for if ( lastCommand == "w") should trigger but it doesn't. The else blocks trigger and it still displays the value that should have caused the if statement to trigger.
Upvotes: 0
Views: 375
Reputation: 6489
You're using legacy the legacy assign operator and assigning the literal string "q"
(or "w"
) to the variable lastcommand
. As opposed to assigning the string q
or w
.
The fix? Never use the legacy assigning operator =
(docs), use the modern expression assign operator instead :=
(docs).
Upvotes: 3