How to toggle between two Autohotkey configurations -
i need toggle between 2 autohotkey key mapping configurations. i'd toggle 2 through f3. research online , on stackoverflow, think below should want:
#ifwinactive next_make_mac = %1% msgbox next_make_mac: %next_make_mac% #if next_make_mac msgbox setting mac settings. ralt::control escape::delete rwin::escape lwin::lalt lalt::lwin next_make_mac := false msgbox mac settings set. #if #if !next_make_mac msgbox setting pc settings. ralt::escape msgbox pc settings set. next_make_mac := true #if msgbox %next_make_mac% f3:: run %a_ahkpath% %a_scriptname% %next_make_mac% return
however, #if next_make_mac
directive evaluates true. i'm not sure why is. in fact, if slip in next_make_mac := false
still evaluates true. there better way i'm doing?
i'm running autohotkey 1.1.21.03
first of all, message-boxes have inside #if
statements not behave expected. first one, on line 7 go off, telling it's setting mac settings
. hotkeys however, setup properly.
i think due auto-exec section reaching way first hotkey finds.
only put hotkeys inside #if
statements.
next, in first #if
statement, you're checking if next_make_mac
contains other false
or 0
. meaning string "false"
, evaluate true.
note, false
in ahk same 0
.
in second #if
statement, you're checking if next_make_mac
contains either false
or 0
.
as toggling, since can't change values of variables directly inside #if
statements, you'll have add f3 hotkey.
like this:
f3:: next_make_mac := !next_make_mac ; flip value msgbox % next_make_mac run %a_ahkpath% %a_scriptname% %next_make_mac% return
that line toggle next_make_mac
, assuming contains either true
, false
, 1
or 0
.
so, make sure have hotkeys inside #if
statements, , pass 1
or 0
params instead of true
or false
don't accidentally use string, , script should work expected.
here's full example of changes:
#singleinstance, force #ifwinactive next_make_mac = %1% ; check settings we'll using if (next_make_mac) msgbox, using mac settings else msgbox, using pc settings ; hotkeys inside here #if next_make_mac ralt::control escape::delete rwin::escape lwin::lalt lalt::lwin #if ; hotkeys inside here #if !next_make_mac ralt::escape #if f3:: next_make_mac := !next_make_mac ; flip value run %a_ahkpath% %a_scriptname% %next_make_mac% return
edit: while outside scope of question, can add #singleinstance, force
@ top of script rid of dialog asks if want restart script every time press f3.
Comments
Post a Comment