October 28, 2021

AutoHotkey: Handling Hotkeys Conflicts

After updating Teams Shortcuts to also support Teams opened in the Web Browser i.e. not only the fat client, I have noticed one other hotkey in another script did not work anymore.

I have leaned thanks to it some differences in AutoHotkey between #IfWinActive and #If Function and the usage of ~ as hotkey modifier.

Problem description

In my TextExpander script, I had a hotkey (alt+q) to paste my email

; alt + q
!q:: ; My Email
SendInput thierry.dalon@gmail.com
return

In Teams Shortcuts I had the same hotkey assigned for another function:

; -------------------------------------------------------------------------------------------------------------------
; Alt+Q
~!q:: ; <--- Quote conversation
QuoteConversation:
Teams_SmartReply(False)
return

In the past these Teams Shortcuts Hotkeys were conditioned with 

#IfWinActive,ahk_exe Teams.exe

and I had no hotkey conflicts

Now it is conditioned by:

#If Teams_IsWinActive()

see previous post)

Explanation 

It seems the #IfWinActive expression is evaluated without running the hotkeys below and there is no hotkeys conflict while using it.

On the contrary if you use a #If Function(), the hotkey is evaluated no matter what, even if the condition is not true and in this case it does simply nothing. Though by the "evaluation" of the hotkey, other conflicting hotkeys are not triggered.

Solution


The solution is to use the ~ modifier before the hotkey as shown below:

; -------------------------------------------------------------------------------------------------------------------
; Alt+Q
~!q:: ; <--- Quote conversation
QuoteConversation:
Teams_SmartReply(False)
return

Conflicting hotkey in second script (TextExpander) will be run if hotkey in first script is not active (TeamsShortcuts).

See also

Avoid key binding conflict among scripts - Ask for Help - AutoHotkey Community

Teams Shortcuts support for browser/ app | Thierry Dalon's Blog

No comments:

Post a Comment