如何在 tauri 中使用 InputBot crate 进行窗口应用?

问题描述 投票:0回答:0

我正在构建 Rust + Angular tauri 应用程序,需要键盘和鼠标的全局输入事件,以便我可以计算笔画和测量活动。

InputBot
板条箱很好,可以用于终端应用程序。对于窗口应用程序,它不工作并且应用程序变得无响应。

这是我尝试过的:


fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![
           screenshot
        ])
        .on_window_event(|event| match event.event() {
            tauri::WindowEvent::CloseRequested { api, .. } => {
              event.window().hide().unwrap();
              api.prevent_close();
            }
            _ => {}
          })
        .setup(|app| {
         
             // Bind all keys to a common callback event.
             KeybdKey::bind_all(|event| {
               match inputbot::from_keybd_key(event) {
                 Some(c) => println!("{c}"),
                 None => println!("Unregistered Key"),
               };
             });


            // Bind all mouse buttons to a common callback event.
            MouseButton::bind_all(|event| {
                println!("{:?}", event);
            });
          
            // Call this to start listening for bound inputs.
            inputbot::handle_input_events(); // -> this line makes app unresponsive.
        
            Ok(())
        })
        .build(tauri::generate_context!())
        .expect("error while running tauri application")
        .run(|_app_handle, event| match event {
            tauri::RunEvent::ExitRequested { api, .. } => {
              api.prevent_exit();
            }
            _ => {

            }
          });

}

rust keyboard-events tauri
© www.soinside.com 2019 - 2024. All rights reserved.