Expand description
§prevent-alt-win-menu
Prevents the menu bar or Start menu from appearing when the Alt or Windows key is released on Windows.
§Overview
On Windows, releasing the Alt key typically activates the menu bar of the focused
window (if it has one), and releasing the Windows key opens the Start menu.
This crate allows you to suppress these behaviors, which is useful for apps with
custom global keyboard handling or immersive fullscreen UIs.
§Platform
- Windows only
§Quick Start
Call start at the beginning of your application. You do not need to hold on
to the returned JoinHandles unless you explicitly want to join() the threads
or detect their termination.
use prevent_alt_win_menu::event_handler::Config;
use prevent_alt_win_menu::start;
// Starts the suppression logic in background threads
let _ = start(Config::default()).expect("failed to start menu suppression");§How it works
This crate installs a low-level keyboard hook using SetWindowsHookExW and listens
for WM_KEYUP events of:
-
VK_MENU/VK_LMENU/VK_RMENU(Alt key) -
VK_LWIN/VK_RWIN(Left/Right Windows key)
When such a key is released, a dummy key-up event (by default, VK__none_) is programmatically
sent immediately.
This causes Windows to interpret the input as a hotkey sequence rather than a standalone
key release — effectively suppressing the default menu activation behavior.
§Configuration
-
Custom dummy key: You can specify any virtual key code to be used as the dummy key.
-
Conditional suppression: A callback function allows you to decide at runtime whether or not to send the dummy key, based on the released key or app state.
§Limitations
- May interfere with other hooks that rely on raw
AltorWinkey events.
§License
MIT OR Apache-2.0
Modules§
- error
- event_
handler - Process keyboard events and suppress menu activation, providing interfaces for customization.
- keyboard_
hook - Low-level module for starting a global keyboard hook on Windows.
Structs§
- Join
Handles - Pair of thread handles for the keyboard hook and event handler.
Functions§
- start
- Starts keyboard hook and event handler threads to suppress the Alt or Windows menu.