Narsil / rdev

Simple library to listen and send events to keyboard and mouse (MacOS, Windows, Linux)
MIT License
503 stars 124 forks source link

Meta key does not work #142

Closed 0PandaDEV closed 2 months ago

0PandaDEV commented 3 months ago

The MetaLeft and MetaRight key do both not work for me they just wont trigger anything.

use rdev::{listen, EventType, Key};
use std::sync::mpsc;
use tauri::Manager;

pub fn setup(app_handle: tauri::AppHandle) {
    let (tx, rx) = mpsc::channel();

    std::thread::spawn(move || {
        listen(move |event| {
            tx.send(event).unwrap();
        })
        .unwrap();
    });

    std::thread::spawn(move || {
        let mut meta_pressed = false;

        while let Ok(event) = rx.recv() {
            match event.event_type {
                EventType::KeyPress(Key::MetaLeft) | EventType::KeyPress(Key::MetaRight) => {
                    meta_pressed = true;
                    println!("Meta key pressed");
                }
                EventType::KeyRelease(Key::MetaLeft) | EventType::KeyRelease(Key::MetaRight) => {
                    meta_pressed = false;
                    println!("Meta key released");
                }
                EventType::KeyPress(Key::KeyV) => {
                    println!("V key pressed");
                    if meta_pressed {
                        println!("Meta+V detected");
                        let window = app_handle.get_window("main").unwrap();
                        let is_visible = window.is_visible().unwrap();
                        if is_visible {
                            println!("Hiding window");
                            window.hide().unwrap();
                        } else {
                            println!("Showing window");
                            window.show().unwrap();
                            window.set_focus().unwrap();
                        }
                    }
                }
                _ => {}
            }
        }
    });
}
0PandaDEV commented 2 months ago

For some reason, it fixed itself