Gordon Wells
Gordon Wells

Reputation: 346

How to prevent key combo subset from overriding superset in autohotkey

I'm new to autohotkey, but can't seem to find a way to stop this

How do I prevent a key combination subset from over-riding the windows default superset?

I want to bind Rwin+Right to Alt+Tab without breaking the default Ctrl+Rwin+Right desktop switching

Upvotes: 1

Views: 411

Answers (2)

Relax
Relax

Reputation: 10603

; Rwin+Right
>#Right::                 ; ># means RWin
    AltTabMenu := true    ; assign the Boolean value "true" to this variable
    Send {RWin Down}{Alt Down}{Tab}
return

; The #If directive creates context-sensitive hotkeys:

#If (AltTabMenu)         ; If this variable has the value "true"

    ; The tilde prefix (~) prevents AHK from blocking the key-down/up events
    ; The * prefix fires the hotkey even if extra modifiers (in this case Alt) are being held down
    ~*RWin Up::             
        Send {Blind}{Alt Up} ; release Alt
        AltTabMenu := false
    return

#If

EDIT:

Added {RWin Down} to the command Send {Alt Down}{Tab} because of

[v1.1.14+]: If the tilde prefix is applied to a custom modifier key (prefix key) which is also used as its own hotkey, that hotkey will fire when the key is pressed instead of being delayed until the key is released.

https://autohotkey.com/docs/commands/_If.htm

https://autohotkey.com/docs/Hotkeys.htm#Symbols

https://autohotkey.com/docs/Hotkeys.htm#Tilde

Upvotes: 1

J. G.
J. G.

Reputation: 1832

I think it can be even simpler than that:

#Right:: Send {Alt Down} {Tab}{Alt Up}
#^Right:: Send {Ctrl Down}{Rwin Down} {Right} {Rwin Up}{Ctrl Up}

Upvotes: 0

Related Questions