Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My question is how to structure key combinations in the script below most effectively using AutoHotkey.

Having searched for exactly how to do this for hours I figured I should post here so others can at least find this solution if they are trying to do the same: http://www.autohotkey.com/board/topic/90013-solved-wasd-fna-left-fnalta-home-fnctrla-ctrl-left-etc/ and How to combine three keys as a hotkey with Autohotkey?

My Question is how to use this method most effectively, and is not answered in those threads. My idea would be to use this for everything related to up (etc), e.g.:

; Up Combinations: Ctrl Up, SHIFT + Up, SHIFT + Ctrl Up, [Alt/win + Up easily 
; added and organized using this system]
CapsLock & w::
GetKeyState, stateCtrl, LCtrl
GetKeyState, stateShift, LShift
GetKeyState, stateWin, LWin
GetKeyState, stateAlt, LAlt
    if stateCtrl = D
        if stateShift = D
            if stateWin = D
                Send ^+#{Up}; Ctrl + SHIFT + Win + Up
            else
                Send ^+{Up}    ; Ctrl + SHIFT + Up
        else if stateWin = D
            Send ^#{Up}    ; Ctrl + Win + Up
        else
            Send ^{Up}    ; Ctrl Up
    else if stateShift = D
        Send +{Up}    ; SHIFT + Up
    else if stateWin = D
        Send #{Up}    ; Win + Up
    else if stateAlt = D
        Send !{Up}    ; Alt + Up
    else
        Send {Up}    ; Up
return

Also, if there is a better way to do this, that would be great. E.g.:

*CapsLock & w:: send {Up}

Does almost exactly the opposite of what I want (sends up even if other modifiers are held down). When I hold e.g. control at the same time, I want it to do control + up. Have I missed such a AutoHotkey command?

If anyone has a better way to do this that would be great.

share|improve this question

1 Answer 1

After further study there seems to be no easier way to do this, and since any decent text editor can deal with this I guess this will have to do.

; Up Combinations: Ctrl Up, SHIFT + Up, SHIFT + Ctrl Up, [Alt/win + Up easily added and organized using this system]
CapsLock & w::
GetKeyState, stateCtrl, LCtrl
GetKeyState, stateShift, LShift
GetKeyState, stateWin, LWin
GetKeyState, stateAlt, LAlt
;[ad infinitum, making it possible to combine as many keys you want 
;Followed by a very long, nested, upgly looking if statement

One example (all this is required for one single key, very inefficient!):

SC056 & h:: ; this is doing same thing, but instead of capslock it uses another 
;modifying key (ergo this can use capslock as modifier, but makes conflicts possible)
GetKeyState, stateCtrl, LCtrl
GetKeyState, stateShift, LShift
GetKeyState, stateWin, LWin
GetKeyState, stateAlt, LAlt
    if stateCtrl=D
        if stateShift=D
            if stateWin=D
                if stateAlt=D
                    send ^+!#{home} ; Ctrl + SHIFT + alt + Win + home
                else
                    Send ^+#{home} ; Ctrl + SHIFT + Win + home
            else if stateAlt=D
                send ^+!{home} ; Ctrl + SHIFT + alt + home
            else
                Send ^+{home}   ; Ctrl + SHIFT + home
        else if stateWin=D
                if stateAlt=D
                    send ^+#{home} ; Ctrl + shift + Win + home
                else
                    Send ^#{home}   ; Ctrl + win + home
        else if stateAlt=D
            if stateWin=D
                send ^!#{home} ; Ctrl + alt + win + home
            else
                send ^!{home} ; Ctrl + alt + home
        else if stateWin=D
                send ^#{home} ; Ctrl + win + home
        else
            Send ^{home}    ; Ctrl home
    else if stateShift=D
            if stateWin=D
                if stateAlt=D
                    send +!#{home} ; SHIFT + alt + Win + home
                else
                    Send +#{home} ; SHIFT + Win + home
            else if stateAlt=D
                send +!{home} ; SHIFT + alt + home
            else
                Send +{home} ; SHIFT + home
    else if stateWin=D
            if stateAlt=D
                    send !#{home} ; alt + Win + home
            else
                Send #{home} ; Win + home
    else if stateAlt=D
        Send !{home} ; Alt + home
    else
        Send {home} ; home
return
share|improve this answer
    
I have an issue with this! When using Pseudocode: GetKeyState, stateCtrl, LCtrl if stateCtrl = D Send ^{Enter} ; Ctrl Enter return I have the issue that when using this when clicking on links (i.e. ctrl+enter), it clicks enter first, and then clicks ctrl + enter, meaning that this isn't working the way I want it do I need to have it sleep to get this to work? –  Stenemo Jun 19 at 8:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.