Alt-Tab Macro Automation Issue

I’m attempting to setup a macro that does the following:

When tapped once, alt-tab
When double-tapped, it will hold down the alt key, press tab once, and continue holding the alt key indefinitely
When pressed again after a double tap, it will release the alt key

This is what I’ve got so far, which works as far as getting into the held state, but it seems like I’m confused about the keycode for alt, and possible about the lifecycle of holdkey?

The single alt-tab works, but the alt hold does not, additionally it’s been sending the letter A instead of alt


ifDoubletap {
    if ($altTabState == 0) {
        holdKey A
        tapKey tab
        setVar altTabState 1
        exit 
    }
} 
else {
    if ($altTabState == 1) {
        releaseKey A
        setVar altTabState 0
    }
    else {
        tapKey A-tab
    }
}

Well:

  • A means shift+a; To denote alt, use LA, meaning Left Alt
  • holdKey presses key, waits until you release the key that activated the macro and then releases the key. Just then the macro continues to further commands, so this effectively yields press alt, wait for some time, release alt, press tab, release tab. You want to use pressKey LA instead. Also, I see no reason to not use simply holdKey LA-tab instead of the two commands.
  • Also, in order to hold a key indefinitely, you will need to use active waiting, as all scancodes activated within a macro are released when the macro ends.

I think this should work:

ifDoubletap {
    setVar altTabState 1
    pressKey LA
    while ($altTabState == 1) {
        delayUntil 10
    }
} 
else {
    if ($altTabState == 1) {
        setVar altTabState 0
    } 
    else {
        holdKey LA-tab
    }
}
1 Like

I managed to get this where I needed after a slight modification

ifDoubletap {
    setVar altTabState 1
    pressKey LA
    tapKey tab
    while ($altTabState == 1) {
        delayUntil 10
    }
} 
else {
    if ($altTabState == 1) {
        setVar altTabState 0
    }
    else {
        holdKey LA
        tapKey LA-tab
    }
}

Now I can tap a button to do a standard alt-tab, or double tap the button to keep the alt-tab menu on-screen, allowing me to tab to the selection I want and then exit the menu with another tap.

As an aside, the editor yells at you if the else is on the same line as the closing bracket:

} else {

Thanks Karel!

1 Like

Oops, sorry about that, you are completely right!

1 Like