tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] Issue with global shortcuts

Open Donnwill opened this issue 2 years ago • 10 comments

Describe the bug

I am using react, typescript, Tauri as my frontend. I am facing problems with the global shortcuts. The shortcut works for an English layout keyboard and when the same shortcut is used on a German keyboard it doesn't work. For example, the Y and Z keys are switched. In English keyboard if the shortcut is Z and for the German keyboard its Y, but it should be If Z is for English layout, Z should be for German layout too. How can I fix this. Is it possible to detect which keyboard layout is being used?

Reproduction

Create a shortcut Shift+Z from your German keyboard layout, Which is Shift+Y in the english keyboard, it is registered as Shift+Z, When you press Shift+Z from your German keyboard it doesnt work, but if you press Shift+Y it works. This should not happen

Expected behavior

When Shift+Z is the Shortcut and Shift+Z is pressed in German keyboard it should work

Platform and versions

- OS: Mac OS 13.1.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.66.1 (90743e729 2023-01-10)
    ✔ Cargo: 1.66.1 (ad779e08b 2023-01-10)
    ✔ rustup: 1.25.1 (bb60b1e89 2022-07-12)
    ✔ Rust toolchain: stable-x86_64-apple-darwin (default)
    - node: 18.16.0
    - yarn: 1.22.19
    - npm: 9.5.1
 Packages
    - tauri [RUST]: 1.2.4
    - tauri-build [RUST]: 1.2.1
    - wry [RUST]: 0.23.4
    - tao [RUST]: 0.15.8
    - @tauri-apps/api [NPM]: 1.3.0
    - @tauri-apps/cli [NPM]: 1.3.0 (outdated, latest: 1.3.1)
App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:5173/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

Donnwill avatar Jun 07 '23 12:06 Donnwill

I don't really know how to approach this issue to be honest since there is a lot of different layouts and if you register Ctrl+Z (the key on the left bottom) and use that combo to trigger the app then some time after, you switch to a german layout and now your brain has to adjust and remember a different key combo for the same app, doesn't sound very intutive to me.

I don't see a way to easily support this tbh and I don't think the OS allows it.

amrbashir avatar Jun 07 '23 13:06 amrbashir

Try the German layout, set a shortcut Shift+z the German layout and try it. It won't work

Donnwill avatar Jun 07 '23 13:06 Donnwill

Actually, if i understand it correctly then macOS and Windows behave differently here. Trying it on Windows the shortcut will follow the layout, meaning i have to press different physical keys for ctrl+y depending on if i use qwerty and qwertz.

for what it's worth, vscode behaves the same (ctrl+z/y being physically different per layout)

So idk, if we don't count this as a bug we're at least dealing with platform differences here 🤔

FabianLars avatar Jun 07 '23 14:06 FabianLars

So you are saying it's a MacBook issue? And there are issues with platforms ?

Donnwill avatar Jun 07 '23 14:06 Donnwill

Alright, I will mark this as macOS specific issue, I think the correct behavior sould be that ctrl+ z (the left-bottom most key) should work with the same key location regardless of the layout change

amrbashir avatar Jun 07 '23 14:06 amrbashir

Thank you

Donnwill avatar Jun 07 '23 14:06 Donnwill

I think the correct behavior sould be that ctrl+ z (the left-bottom most key) should work regardless of the layout

In this case it's a windows specific issue. The left-bottom most key only triggers the shortcut if the registered shortcut matches the virtual key/layout for me on Windows. So macOS does it right? (that's not something i hear me say often 😂)

To be specific: If i register Ctrl+Z:

  • qwerty layout: I have to press bottom left key
  • qwertz (german) layout: I have to press the key next to T (y on qwerty)

FabianLars avatar Jun 07 '23 14:06 FabianLars

no no, I mean the windows behavior is the correct one, macOS is the messed up one.

amrbashir avatar Jun 07 '23 15:06 amrbashir

I have a question. I've been trying it out in windows with German layout, when I add special characters such as ö, ä, which are a part of German characters and register the shortcuts and I get the following error: thread 'tokio-runtime-worker' panicked at 'invalid accelerator: AcceleratorParseError("Couldn't identify "ö" as a valid KeyCode")', C:\Users\donn2.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-runtime-wry-0.12.2\src\global_shortcut.rs:77:60

Is this intended or an issue ?

Donnwill avatar Jun 08 '23 08:06 Donnwill

It is intended, you should be writing the character in english layout

amrbashir avatar Jun 08 '23 10:06 amrbashir