kbd-tao 0.1.0

tao bridge for kbd — converts tao key events and modifiers to kbd types.
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented4 out of 8 items with examples
  • Size
  • Source code size: 90.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.19 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 55s Average build duration of successful builds.
  • all releases: 1m 55s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • joshuadavidthomas/kbd
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • joshuadavidthomas

kbd-tao

crates.io docs.rs

kbd bridge for tao (Tauri's winit fork) — converts key events and modifiers to kbd types.

This lets window-focused key events (from tao) and global hotkey events (from kbd-global) feed into the same Dispatcher. Especially useful in Tauri apps where you want both in-window shortcuts and system-wide hotkeys handled through a single hotkey registry.

Tao is Tauri's fork of winit — both derive from the W3C UI Events specification, so the variant names are nearly identical and the mapping is mechanical. Unlike winit, tao uses KeyCode directly in KeyEvent rather than wrapping it in a PhysicalKey type.

[dependencies]
kbd = "0.1"
kbd-tao = "0.1"

Extension traits

  • TaoKeyExt — converts a tao KeyCode to a kbd::Key
  • TaoModifiersExt — converts tao ModifiersState to a Vec<Modifier>
  • TaoEventExt — converts a tao KeyEvent plus ModifiersState to a kbd::Hotkey

Usage

Inside tao's event loop, use TaoEventExt to convert key events directly:

use kbd::prelude::*;
use kbd_tao::TaoEventExt;
use tao::event::{Event, WindowEvent};
use tao::event_loop::{ControlFlow, EventLoop};
use tao::keyboard::ModifiersState;
use tao::window::WindowBuilder;

let event_loop = EventLoop::new();
let _window = WindowBuilder::new().build(&event_loop).unwrap();
let mut modifiers = ModifiersState::empty();

event_loop.run(move |event, _, control_flow| {
    *control_flow = ControlFlow::Wait;
    if let Event::WindowEvent { event, .. } = event {
        match event {
            WindowEvent::ModifiersChanged(mods) => modifiers = mods,
            WindowEvent::KeyboardInput { event, .. } => {
                if let Some(hotkey) = event.to_hotkey(modifiers) {
                    println!("{hotkey}");
                }
            }
            _ => {}
        }
    }
});

The individual conversion traits can also be used separately:

use kbd::prelude::*;
use kbd_tao::{TaoKeyExt, TaoModifiersExt};
use tao::keyboard::{KeyCode, ModifiersState};

let key = KeyCode::KeyA.to_key();
assert_eq!(key, Some(Key::A));

let mods = ModifiersState::CONTROL.to_modifiers();
assert_eq!(mods, vec![Modifier::Ctrl]);

Key mapping

tao kbd Notes
KeyCode::KeyAKeyCode::KeyZ Key::AKey::Z Letters
KeyCode::Digit0KeyCode::Digit9 Key::DIGIT0Key::DIGIT9 Digits
KeyCode::F1KeyCode::F35 Key::F1Key::F35 Function keys
KeyCode::Numpad0KeyCode::Numpad9 Key::NUMPAD0Key::NUMPAD9 Numpad
KeyCode::Enter, KeyCode::Escape, … Key::ENTER, Key::ESCAPE, … Navigation / editing
KeyCode::ControlLeft, … Key::CONTROL_LEFT, … Modifier keys as triggers
KeyCode::SuperLeft / KeyCode::SuperRight Key::META_LEFT / Key::META_RIGHT tao's Super = kbd's Meta
KeyCode::Equal / KeyCode::Plus Key::EQUAL Same physical key
KeyCode::MediaPlayPause, … Key::MEDIA_PLAY_PAUSE, … Media keys
KeyCode::BrowserBack, … Key::BROWSER_BACK, … Browser keys
KeyCode::Unidentified(_) None No mapping possible

Modifier mapping

tao kbd
CONTROL Modifier::Ctrl
SHIFT Modifier::Shift
ALT Modifier::Alt
SUPER Modifier::Super

License

kbd-tao is licensed under the MIT license. See the LICENSE file for more information.