A lightweight and ergonomic rust crate to handle system-wide hotkeys on windows

Overview

Windows Hotkeys

Crates.io Crates.io Docs.rs

An opinionated, lightweight crate to handle system-wide hotkeys on windows

The windows-hotkeys crate abstracts and handles all interactions with the winapi, including registering hotkeys and handling the events. A hotkey manager instance is used to register key combinations together with easy callbacks.

Features

  • Full highlevel abstraction over the winapi functions and events
  • Easy to use
  • Register hotkeys with Key + Modifier
  • Register hotkeys with Key + Modifier and require additional keys to be pressed at the same time
  • Set rust callback functions or closures that are executed on hotkey trigger
  • High level rust abstractions over the Virtual Keys (VK_* constants) and Modifier Keys (MOD_* constants)
  • Create VKeys (Virtual Keys) and ModKeys (Modifier Keys) from key name strings

How to use

  1. Create a HotkeyManager instance
  2. Register a hokey by specifying a VKey and one or more ModKeys, together with a callback
  3. Run the event loop to react to the incomming hotkey triggers
use windows_hotkeys::keys::{ModKey, VKey};
use windows_hotkeys::HotkeyManager;

fn main() {
    let mut hkm = HotkeyManager::new();

    hkm.register(VKey::A, &[ModKey::Alt], || {
        println!("Hotkey ALT + A was pressed");
    })
    .unwrap();

    hkm.event_loop();
}

Current limitations

Threading

Due to limitations in the windows API, hotkey events can only be received and unregistered on the same thread as they were initially registered. This means that a HotkeyManager instance can't be moved between threads.

Using windows-hotkeys with multithreading is still possible, but the HotkeyManager must be created and used on the same thread.

A possible solution to this limitation might be to have each HotkeyManager run it's own thread in the backgroud that is used to register, unregister and listen for hotkeys. This might be implemented in the future and would provide a more ergonomic way to use the HotkeyManager in general.

You might also like...
A Rust crate for parsing Windows user minidumps.
A Rust crate for parsing Windows user minidumps.

udmp-parser-rs: A Rust crate for parsing Windows user minidumps This is a cross-platform crate that parses Windows user minidump dumps that you can ge

First project in rust which will be to make an accounts system & Leaderboard/Score system

rust-backend this is my first project in rust which will be to make a backend for compsci project it will include: Accounts, Player Achievements (if I

A small Rust library that let's you get position and size of the active window on Windows and MacOS

active-win-pos-rs A small Rust library that let's you get position and size of the active window on Windows and MacOS Build % git clone https://github

Adds back-and-forth jumping between current and previous focused windows to Sway.

sway-focus-back-and-forth Implements back-and-forth movement between the current and the previous focused windows. It also can be seen as a fix to thi

Maccha is an extremely extensible and themable power menu for Windows, macOS, and Linux.

Maccha I hate coffee. Maccha is an extremely extensible and themable power menu for Windows, macOS, and Linux. Plugins Plugins are written in Rust (ot

Web-based tool that allows browsing and comparing symbol and type information of Microsoft Windows binaries across different versions of the OS.
Web-based tool that allows browsing and comparing symbol and type information of Microsoft Windows binaries across different versions of the OS.

WinDiff About WinDiff is an open-source web-based tool that allows browsing and comparing symbol and type information of Microsoft Windows binaries ac

Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev

Tailwind-Leptos-Tauri Template Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev Just clone the rep

A lightweight but incredibly powerful and feature-rich BitTorrent tracker. Supports UDP + HTTP(S) and a private tracker mode.

Torrust Tracker Project Description Torrust Tracker is a lightweight but incredibly powerful and feature-rich BitTorrent tracker made using Rust. Feat

A Rust curses library, supports Unix platforms and Windows

pancurses pancurses is a curses library for Rust that supports both Linux and Windows by abstracting away the backend that it uses (ncurses-rs and pdc

Releases(v0.1.0)
Owner
null
A high-level, ergonomic crate for interacting with the UploadThing API

utapi-rs A high-level, ergonomic Rust crate for interacting with the Uploadthing API. Why? If you're using Rust and want to use Uploadthing for file u

Ivan Leon 4 Feb 2, 2024
A handy way to handle sh/bash cli parameters

Argc A handy way to handle sh/bash cli parameters. How Argc works To write a command line program with Argc, we only need to do two things: Describe t

null 398 Jan 3, 2023
Use raw-window-handle 0.5 with crates that depend on 0.4.

OldHasRawWindowHandleWrapper Wrap any type that implements HasRawWindowHandle and HasRawDisplayHandle from raw-window-handle 0.5 in OldHasRawWindowHan

null 1 Nov 25, 2022
Use Thunk to build your Rust program that runs on old Windows platforms, support Windows XP and more!

Use Thunk to build your Rust program that runs on old platforms. Thunk uses VC-LTL5 and YY-Thunks to build programs that support old platforms. So, ho

null 6 May 21, 2023
Windows-rs - Rust for Windows

Rust for Windows The windows crate lets you call any Windows API past, present, and future using code generated on the fly directly from the metadata

Microsoft 7.7k Dec 30, 2022
Switch windows of same app with alt + ` on windows pc.

Windows Switcher Switch windows of same app with alt + ` on windows pc. 250k single file executable downloaded from Github Release. No installation re

null 172 Dec 10, 2022
Check if the process is running inside Windows Subsystem for Linux (Bash on Windows)

is-wsl Check if the process is running inside Windows Subsystem for Linux (Bash on Windows) Inspired by sindresorhus/is-wsl and made for Rust lang. Ca

Sean Larkin 6 Jan 31, 2023
Windows Capture Simple Screen Capture for Windows 🔥

Windows Capture   Windows Capture is a highly efficient Rust library that enables you to effortlessly capture the screen using the Graphics Capture AP

null 3 Sep 24, 2023
Rust crate to enable ANSI escape code support on Windows.

enable-ansi-support: Enable ANSI escape code support on Windows 10 About This crate provides one function, enable_ansi_support, which allows ANSI esca

Rain 9 Nov 18, 2022
Rust crate for interacting with the Windows Packet Filter driver.

NDISAPI-RS NDISAPI-RS is a Rust crate for interacting with the Windows Packet Filter driver. It provides an easy-to-use, safe, and efficient interface

Vadim Smirnov 6 Jun 15, 2023