Can't override windows key with tauri window focused

67 views Asked by At

I want to install a windows hook for overriding the windows key. This is the code I have written.

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use mki::{bind_key, Action, InhibitEvent, Keyboard};

fn main() {

  bind_key(Keyboard::LeftWindows, Action {
    callback: Box::new(|_event, _state| {
      println!("Left Windows key pressed");
    }),
    inhibit: InhibitEvent::Yes,
    sequencer: false,
    defer: false,
  });

  bind_key(Keyboard::RightWindows, Action {
    callback: Box::new(|_event, _state| {
      println!("Right Windows key pressed");
    }),
    inhibit: InhibitEvent::Yes,
    sequencer: false,
    defer: false,
  });


  tauri::Builder::default()
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

This works everywhere, except when the Tauri app is in focus, what could be the issue? Does the Tauri windows itself capture the Windows key?

1

There are 1 answers

0
Advait On

I solved this by trail and error.

You need to register a global shortcut for the same key using the Tauri api as well.

  await register('Super', () => {
    console.log('Super was pressed')
  })

Adding this solved the issue where the override worked outside the app, but not when the app is focused.

With this the override works everywhere.