Rewriting Alt-Tab To Save 0.01s | Prime Reacts
Based on The PrimeTime's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
The Alt-Tab replacement uses a keyboard-first model: press an activation key, then type a character tied to the target app name (e.g., “C” for Chrome).
Briefing
A Windows productivity tool that replaces Alt-Tab with single-key switching is built, tested, and then repeatedly optimized—only to run into performance limits on another machine. The core idea is simple: instead of hunting through a moving task switcher (and losing focus), the user presses the first letter of the target app name—press “C” to jump to Chrome—so program switching becomes fast and low-effort.
The project starts as a prototype that automates keystrokes using AutoHotkey, triggered by a modifier key (right shift). That approach works in principle, but performance and reliability issues show up quickly. From there, the build shifts toward a native Windows app with a minimal UI: a small interface rendered with Windows Forms, created via Visual Studio. The developer’s goal is not a fancy launcher; it’s just enough UI to display text and capture input.
The biggest technical hurdle is capturing keyboard input globally—so the hotkey works even when focus is inside another application (like Candy Crush Saga). The solution is a low-level keyboard hook, which intercepts keystrokes system-wide. Once the hook is in place, pressing the activation key successfully brings up the switcher behavior.
Next comes the window-switching logic. The tool enumerates open windows using EnumWindows, then filters out “non-sane” entries—effectively ignoring windows that aren’t real targets (the taskbar, battery meter, and other always-on UI elements). With the list of candidate windows assembled, the switcher can attempt to activate the correct app.
But the system reveals edge cases under real use. If the hotkey is pressed too quickly during startup, the key press can be missed. The initial suspicion falls on UI responsiveness, and the developer concludes Windows Forms is too slow for the timing requirements. That triggers a major rewrite: instead of relying on Windows Forms for UI handling, the app draws directly using GDI primitives. The result is a working switcher with faster, more predictable rendering—at the cost of redoing the UI responsibilities that Windows Forms previously handled.
Two remaining functional problems then surface. First, letter conflicts occur when multiple apps share the same activation letter (two programs both starting with “C”), forcing the tool to assign alternate activation keys for duplicates. Second, configuration becomes necessary: a JSON config file lets users map app names or aliases (like “Chrome” or “browser”) to the desired activation behavior.
After all that, the tool finally delivers the promised “bliss” of not using Alt-Tab. Yet the final test—handing it to a brother—shows the performance bottleneck persists on other hardware. The switcher is still too slow there, ending the build with the decision to rewrite again, this time driven by speed constraints rather than feature gaps.
Cornell Notes
The project replaces Alt-Tab with a hotkey-driven app switcher that activates programs by typing the first letter of the app name (e.g., “C” for Chrome). It evolves from an AutoHotkey prototype into a native Windows app built with Windows Forms, then adds a low-level keyboard hook so hotkeys work even when other apps are focused. Window switching relies on enumerating open windows via EnumWindows and filtering out non-target UI windows. When timing and responsiveness issues appear—especially during fast key presses—the UI layer is rewritten using GDI for direct drawing. The final behavior includes handling duplicate-letter conflicts and storing mappings in a JSON config, but performance still lags on another PC, prompting another rewrite.
Why does the project move away from Alt-Tab, and what workflow does it replace?
What role does the low-level keyboard hook play in making the switcher usable system-wide?
How does the switcher decide which windows are valid targets?
Why was Windows Forms replaced with GDI, and what changed technically?
What happens when two apps share the same activation letter, and how is it handled?
How does configuration work, and what does it enable?
Review Questions
- What limitation of Windows Forms keyboard input makes a low-level keyboard hook necessary?
- Describe the filtering problem when enumerating windows with EnumWindows and how the project addresses it.
- Why does duplicate-letter activation (e.g., multiple “C” apps) require additional logic beyond first-letter switching?
Key Points
- 1
The Alt-Tab replacement uses a keyboard-first model: press an activation key, then type a character tied to the target app name (e.g., “C” for Chrome).
- 2
A low-level keyboard hook is required so hotkeys work even when focus is inside other applications, not just when the switcher window is active.
- 3
Window switching is built on EnumWindows, followed by filtering to exclude non-target always-on UI windows like the taskbar and battery meter.
- 4
Performance and timing issues can force a UI rewrite: Windows Forms may be too slow for rapid hotkey interactions, leading to direct GDI drawing.
- 5
The switcher must handle activation-key collisions when multiple apps share the same initial letter by assigning alternate keys.
- 6
A JSON config file enables user-defined mappings and aliases (e.g., mapping “browser” to the Chrome target).
- 7
Even after major optimization, the tool can still be too slow on other hardware, driving the need for another rewrite.