Alt+tab remapped... maybe tap dance?

I’ve been using the Model01 for a couple months now, and the biggest pain that I have is alt+tab being on two different halves. I was hoping to create a macro or find a plugin that would make it easy to remap the alt+tab functionality to just one key, or map to a function key so that it can be pressed from either half.

Has anyone done something similar? How would you map a key-press + modifier, without the key-up of the modifier to something like the tap-dance plugin, or would a custom macro be the best solution?

This information is surprisingly hard to find for something which is very basic and important functionality, so it’s no surprise that you haven’t come across it. Here’s a previous thread about this, but basically of you put LALT(Key_Tab) (Or RALT(Key_Tab), really doesn’t matter) into your keymap wherever you want your alt tab key.

I decided to modify this page to include that information. As I mentioned in the edit notes, not sure what I said is 100% correct nor whether it’s the right or only place to put this information, but I figured having something down somewhere was a good idea and that someone more experienced could clean up and/or move/copy to the right place. @algernon @Jesse

LAlt and RALT both send the key up event, this is not what was aked for. Usually, the Tab+Alt keys initiate a pop up window, allowing you to switch between open applications/windows without using your mouse. You hold Alt and cycle through the windows by tapping the tab key. LALT(Key_Tab) sends the key up event for the Alt key immediately after pressing it, so you can never cycle past the first window.

2 Likes

Ah I get it now.

The problem with having it on just one key would be having a way for windows to know which window to end up on. You could easily do a macro omitting the alt-up of the alt-tab sequence to be able to cycle through windows with each keypress, but you need some way to communicate a final alt-up to indicate your selection unless alt-down has a way of expiring.

I’m pretty sure that also wouldn’t work now. Since idle keys don’t get their event handlers called any more, as soon as you release the macro key, the alt would be released. You could do alt-down, tab-tap, then send a OneShot alt, which ought to keep it pressed, but you’d still need a separate key to end the process and select the window you want.

Alt-tabbing is something that just works better with chording. The best way is probably to have the two keys on different hands.

1 Like

That’s what I was afraid of. Maybe I could combine a qukeys for something that is held longer on the one half, like bksp to become alt, and then use tab as normal. would this work?

You can have a macro that sets a flag, and then in your loop() (or if you use the plugin API, in beforeReportingState()), you inject Alt+Tab.

Wouldn’t this have the same key-down/key-up problem?

Nope. Here’s an - untested - attempt:

namespace kaleidoscope {
class AltTabber : public kaleidoscope::Plugin {
public:
  AltTabber() {}
  EventHandlerResult beforeReportingState();

  static uint8_t step;
}:

uint8_t AltTabber::step;

EventHandlerResult AltTabber::beforeReportingState() {
  if (step == 0)
    return EventHandlerResult::OK;

 if (step == 1) {
    handleKeyswitchEvent(LALT(Key_Tab), 
                         UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
    step++;
 } else {
    handleKeyswitchEvent(Key_LeftAlt,
                         UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
 }
 return EventHandlerResult::OK;
}
}

kaleidoscope::AltTabber AltTabber;

void macroAltTabber(uint8_t keyState) {
  if (!keyToggledOn(keyState))
    return;

  if (AltTabber.step == 0) {
    AltTabber.step = 1;
  } else {
    handleKeyswitchEvent(Key_Tab, 
                         UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
  }
}

This creates a macro which when you press it first, will set a flag, and the plugin will then send an Alt+Tab, and switch to its next state. It will continue holding Alt until something turns that off (more on that later). When you press the macro key again, it will press Tab, and the plugin will add the Alt.

Now, you only need a way to turn this off… you could turn Enter into a macro that sends Enter normally, unless AltTabber.state is non-zero. In which case it sets it to zero. This way you can use Enter to select the application.

2 Likes

I know this is an old topic but I found its content quite useful as a new user.

I actually went down the path @algernon offers and completed it to a tested attempt. I go more in depth here.

For those searching for a working example, here is my current firmware Model01-Firmware.ino (11.3 KB)
It uses one shot modifier and some tap dance, but it does not require any third party plugin.

1 Like