Stenemo
Stenemo

Reputation: 619

AutoHotkey - maximizing number of keyboard kombinations with limited set of keys

I want to set up a AutoHotkey system that uses as few keys as possible to have access to many (e.g. 100) key combinations

For beginners: Here is one good example of how to do the more basic command. Another good method is mentioned here, both of which I am looking to combine and expand upon into a more comprehensive system.

To clarify this question: I have for example 3 keys: a, b, and c. What would be a good way to get the most usage out of only these 3 keys?

To keep it simple, here are 3 examples of ways to use only 3 keys I have thought of:

The second part of this is how to program AutoHotkey to do this without risking conflicts later when you add a fourth key, etc.

One way I have tried to do this before is to use keystate , and should be straight forward for most when using double click. Here is my work in progress of using this:

CapsLock & a:: ; a hotkey to send a message when you click a two times while 
               ; holding down CapsLock, left Shift, and left Control
GetKeyState, stateLCtrl,    LCtrl
GetKeyState, stateLShift,   LShift
    if stateLCtrl=D
        if stateLShift=D
            if (A_PriorHotkey <> "CapsLock & a" or A_TimeSincePriorHotkey > 500)
            {
                ; Too much time between presses, so this isn't a double-press.
                KeyWait, Esc
                return ; does nothing on single click 
            }
            MsgBox you clicked a two times while holding down 
                   CapsLock, left Shift, and left Control ;output of hotkey 
            return 
        else                
            Return
    else 
        return 
return 

This is just one example, out of many possible ways I can think of how to do this. I think this method is bad for several reasons, so if anyone has a better system that can be easily expanded upon, that would be great!

Upvotes: 2

Views: 572

Answers (1)

Elliot DeNolf
Elliot DeNolf

Reputation: 2999

I would recommend looking into the #If context. This allows you to specify the keystates that you want without duplicating a lot of "state-checking" code. Here is what your script would look like when using this context.

#If GetKeyState("Shift") and GetKeyState("Ctrl") and GetKeyState("CapsLock")
    *a:: 
        Keywait % A_ThisHotkey
        if (A_PriorHotkey = A_ThisHotkey and A_TimeSincePriorHotkey < 500)
            msgbox, short
        else
            return ; too long
    return
#If 
  • Close context with '#If' if you have universal hotkeys after in your script

  • '*' is needed on the hotkey because Ctrl and Shift are considered "modifiers"

Upvotes: 3

Related Questions