wry icon indicating copy to clipboard operation
wry copied to clipboard

CustomMenuItem accelerators don't trigger on_menu_event on Windows

Open adamthrash opened this issue 3 years ago • 9 comments

Describe the bug

CustomMenuItem accelerators in Windows don't trigger on_menu_event, though they do in macOS.

To Reproduce

Steps to reproduce the behavior:

  1. Clone minimal example repository here.
  2. Set up and run app (I use yarn install and yarn tauri dev).
  3. Click File -> Test and note output in terminal. ("test" Test registered!)
  4. Press Ctrl + T and note that output does not appear in terminal.

Expected behavior

Both clicking the menu item and triggering it via its accelerator produce output in the terminal on Windows, since both actions work on macOS.

Screenshots

NA

Platform and Versions (required):

Operating System - Windows, version 10.0.19042 X64
Webview2 - 96.0.1054.41

Node.js environment
  Node.js - 16.13.0
  @tauri-apps/cli - 1.0.0-beta.10
  @tauri-apps/api - 1.0.0-beta.8

Global packages
  npm - 8.1.0
  yarn - 1.22.15

Rust environment
  rustc - 1.56.1
  cargo - 1.56.0

App directory structure
/.git
/node_modules
/public
/scripts
/src
/src-tauri

App
  tauri.rs - 1.0.0-beta.8
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../public/
  devPath - http://localhost:5555
  framework - Svelte
Operating System - Mac OS, version 12.0.1 X64

Node.js environment
  Node.js - 16.9.0
  @tauri-apps/cli - 1.0.0-beta.10
  @tauri-apps/api - 1.0.0-beta.8

Global packages
  npm - 7.21.1
  yarn - 1.22.15

Rust environment
  rustc - 1.55.0
  cargo - 1.55.0

App directory structure
/node_modules
/public
/scripts
/src-tauri
/.git
/src

App
  tauri.rs - 1.0.0-beta.8
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../public/
  devPath - http://localhost:5555
  framework - Svelte
  bundler - Rollup

adamthrash avatar Dec 03 '21 20:12 adamthrash

good news, it works fine in Tao , bad news I can't find any reason why it is not working in Tauri but I can definitely replicate the issue.

amrbashir avatar Dec 04 '21 10:12 amrbashir

Alright, I can replicate it in Wry, seems like the webview hijacks the keyboard events from the underlying win32 window procedure. I will transfer it to Wry.

amrbashir avatar Dec 04 '21 11:12 amrbashir

Does it work if we set it to other shortcut? I think webview2 might occupy a few already. https://weblog.west-wind.com/posts/2021/Apr/15/WebView2-Forwarding-Alt-Keys-to-a-Host-WPF-Window

wusyong avatar Jan 25 '22 10:01 wusyong

I have tried https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2controller?view=webview2-1.0.664.37#add_acceleratorkeypressed but it didn't work. I will look at the article you linked and dig into this again.

amrbashir avatar Jan 25 '22 19:01 amrbashir

Just took a look at the article and it can work (in a hacky way) for Alt only which is not perfect because I found out that sometimes Ctrl combinations don't work.

amrbashir avatar Jan 31 '22 18:01 amrbashir

I will make this as upstream and wait until this is implemented

amrbashir avatar Jan 31 '22 18:01 amrbashir

Being that this has been open since 2021, I wonder if it makes sense to document a workaround? I'm guessing doing something through the frontend Javascript API? Simple key strokes like Ctrl+S for saving don't even work.... Thats kinda a big deal...

tr3ysmith avatar Aug 02 '23 23:08 tr3ysmith

hello,I encountered the same problem. Is there any progress on this issue?

kitty-eu-org avatar Feb 29 '24 09:02 kitty-eu-org

Just took a look at the article and it can work (in a hacky way) for Alt only which is not perfect because I found out that sometimes Ctrl combinations don't work.

Hey, But up until now, the use of accelerators in tauri is null right, i.e., no functionality is added to them? Using Alt is just a substitution here, that too in Windows for exploring the menu-tray.

praball avatar Apr 08 '24 11:04 praball