prevent_alt_win_menu/
lib.rs

1#![doc = include_str!("../README.md")]
2
3pub mod error;
4pub mod event_handler;
5pub mod keyboard_hook;
6
7use std::thread;
8
9use error::Result;
10use event_handler::Config;
11
12/// Starts keyboard hook and event handler threads to suppress the Alt or Windows menu.
13///
14/// This function installs a low-level keyboard hook that listens for key events
15/// and spawns a thread to handle suppression logic. It returns two [`std::thread::JoinHandle`]s:
16/// one for the keyboard hook thread and one for the event handler thread.
17///
18/// You may choose to ignore the returned [`JoinHandles`] entirely.
19/// The suppression behavior will remain active as long as both threads are running.
20///
21/// # Errors
22///
23/// Returns an error if the keyboard hook cannot be registered or the hook thread fails to initialize.
24pub fn start(config: Config) -> Result<JoinHandles> {
25    let (rx, hook_handle) = keyboard_hook::start_keyboard_hook()?;
26    let handler_handle = event_handler::start_event_handler(rx, config);
27
28    Ok(JoinHandles {
29        keyboard_hook: hook_handle,
30        event_handler: handler_handle,
31    })
32}
33
34/// Pair of thread handles for the keyboard hook and event handler.
35///
36/// These are standard [`std::thread::JoinHandle`]s representing background threads
37/// that suppress the system menu triggered by Alt or Windows key releases.
38///
39/// In typical usage, you do not need to hold on to this struct:
40/// the threads will continue running in the background as long as the application does.
41///
42/// However, if you want to explicitly wait for their termination or check for errors,
43/// you can keep and `join()` them as needed.
44pub struct JoinHandles {
45    /// Thread that runs the Windows low-level keyboard hook.
46    pub keyboard_hook: thread::JoinHandle<()>,
47
48    /// Thread that processes keyboard events and performs suppression.
49    pub event_handler: thread::JoinHandle<()>,
50}