Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Mixing hotkeys and remaps leads to unexpected behavior


  • Please log in to reply
No replies to this topic
haxor
  • Members
  • 28 posts
  • Last active: Dec 25 2014 04:57 AM
  • Joined: 22 Jun 2008

This is a bug that arises out of how remaps are made; something that I stumbled into that is unnecessarily confusing.

 

Everything suggests that this should work:

a::Send string
#IfWinActive ahk_class Notepad
a::c

You should expect "a" to normally send "string", but have it remap to "c" within notepad.

It doesn't work, since the remap creates two hotkeys "*a" and "*a up", and "a" takes precedence over "*a" when no modifiers are held.

 

You can fix it like this:

*a::Send string
#IfWinActive ahk_class Notepad
a::c

But it's not quite the same behavior wrt modifiers and it's not clear why the wildcard is necessary. You can also do this:

a::Send string
#IfWinActive ahk_class Notepad
a::
a::c 

Which is even more confusing to read, especially if you have lots of remaps.

 

Neither of these solutions make for logical or readable code.

 

It shouldn't be difficult for AHK, when generating the remap hotkeys, to also generate the bare hotkey (with no wildcard) if there is a conflict, like I did in the second solution. I don't see why it couldn't do this for every conflict.