Search code examples
autohotkey

AHKV1: GetKeyState() not working with #if


The following does not work. The tooltips never fire, when I am holding control:

#singleinstance, force
#Persistent

#If GetKeyState("LControl", "p") 
   WheelUp::
       tooltip, WheelUp + lctrl
       Return
   WheelDown::
       tooltip, WheelDown + lctrl
       Return
#If

But this works, pressing a while ctrl is down fires the tooltip ctrl is down:

#singleinstance, force
#Persistent

*~a::
    if GetKeyState("LControl", "p")
        tooltip, ctrl is down
    else
        tooltip, ctrl is not down

What could I be doing wrong?


Solution

  • Wildcard(*): Fires the hotkey even if extra modifiers (in this case LControl) are being held down.

    #If GetKeyState("LControl", "p") 
    
       *WheelUp:: tooltip, WheelUp + lctrl
       *WheelDown:: tooltip, WheelDown + lctrl
    
    #If
    

    Except in special cases, it is recommended to use the standard syntax:

    <^WheelUp:: tooltip, WheelUp + lctrl
    <^WheelDown:: tooltip, WheelDown + lctrl
    

    See Hotkey Modifier Symbols.