Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globalShortcuts don't work for alternate keyboards on Mac 10.14.6 #19747

Open
Kilian opened this issue Aug 14, 2019 · 12 comments
Open

globalShortcuts don't work for alternate keyboards on Mac 10.14.6 #19747

Kilian opened this issue Aug 14, 2019 · 12 comments

Comments

@Kilian
Copy link
Member

Kilian commented Aug 14, 2019

  • Electron Version:
    • 6.0.2
  • Operating System:
    • mac 10.14.6

Expected Behavior

globalShortcuts work regardless of the chosen keyboard layout

Actual Behavior

On Mac, globalShortcuts seem to default to either qwerty or the keyboards layout (I think? I don't have a dvorak keyboard) rather than the chosen keyboard layout.

To Reproduce

Here's a fiddle that I tested on all three platforms. Windows works perfectly, Linux work with a caveat that it doesn't pick up keyboard changes made while the app is running, and Mac is broken.

https://gist.github.com/Kilian/995123ef2e31d6d15ee147a613831bed

To test this, add dvorak to your keyboard layouts. If set to Dvorak, the l is in the position of the p on a qwerty layout. If you press ctrl + p on a physical qwerty keyboard but are using the dvorak layout that should correspond to ctrl + l and pressing it should give a console.log in fiddle.

@jaga3421
Copy link

I have the same problem. So I replaced global shortcuts with App-specific shortcuts using a library 'Mousetrap'. Works great for me.

https://github.com/ccampbell/mousetrap

@Kilian
Copy link
Member Author

Kilian commented Dec 23, 2020

There are quite a few keys that can't be captured with Mousetrap (like function keys) or other renderer-based libraries, so that's not always an option.

@Kilian Kilian added 10-x-y 11-x-y 8-x-y 9-x-y status/confirmed A maintainer reproduced the bug or agreed with the feature labels Dec 23, 2020
@alexdima
Copy link

In case it is useful, one more data point from #26907: 3.1.13 is the last known good version, 4.0.0-beta.1 is the first bad version.

@clavin
Copy link
Member

clavin commented Feb 26, 2021

Alright, so I did a deep dive on this issue. 🧠💥

First, this particular issue did not work in 3.1.13 and never has. Issue #26907 is not exactly the same as this issue, and the two are basically unrelated aside from both being about the codebase assuming a standard US keyboard layout. (I believe the issue #26907 describes possibly did regress between v3 and v4; it's just not the same as this issue, that is all.)

As for this issue, I found that there is pretty much only 1 API on macOS for registering "global hot keys" (aka global keyboard shortcuts)1. That API is named RegisterEventHotKey, it's part of Carbon Events, and it only allows you to register a specific key code (i.e. a physical key, not the character it produces). Further, Carbon was deprecated in 2012 and is pretty much completely unsupported now and this one function just happens to work "well enough" still. I did a lot of searching and compared against libraries in this same domain, and they all rely on essentially this same one API and face the same issue2.

What I'm getting at here is that I don't think this issue can be solved at present. I could not find an API flexible enough to support anything beyond listening for specific key codes (physical keys) everywhere on the system. I think the functionality here is definitely desirable, but I cannot figure out how to make it possible right now. 😕

I didn't search very hard for other apps, but I tested the one other application on my system that has a global keyboard shortcut (it's not Electron-based) and it also suffered this issue.

Edit: anyone who knows their way around macOS APIs is free to @ me and tell me I'm wrong. And I'd love to hear that! I simply did not get anywhere with my own search for a solution here.

Notes
  1. I found only one single other API for this, however it requires accessibility to be enabled for key events.

  2. I found similar open issues in HotKey and in MASShortcut. I also looked at KeyboardShortcuts and although there is not an issue filed that is close to this, I suspect it just hasn't been reported there yet as the source relies on the same Carbon Events API.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2022

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Oct 8, 2022
@andreiciceu
Copy link

andreiciceu commented Oct 13, 2022

bump
still reproducible in the latest version of Electron:

  • use AZERTY layout
  • add a shortcut for Ctrl+W
  • the callback fires for both Ctrl+W and Ctrl+Z

@github-actions github-actions bot removed the stale label Oct 14, 2022
@bmadone
Copy link

bmadone commented Nov 23, 2022

How to fix it? KeyCode is deprecated, code return physical key, so it's not working properly. Any ideas?

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label Feb 22, 2023
@andreiciceu
Copy link

bump, it's still an issue

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

@github-actions github-actions bot added the stale label May 26, 2023
@MelisUnal
Copy link

bump, it's still an issue

@github-actions github-actions bot removed the stale label Jun 7, 2023
@mgulyas42
Copy link

mgulyas42 commented May 14, 2024

bump, it's still an issue.

I tried to configure Ctrl+0 as a hotkey on hungarian keyboard layout. If I pressed 0 I got backquote.

I tried to change layout on linux (Ubuntu) with following command:

setxkbmap -layout hu

And now it is working with Ctrl+0

I'm not sure why the app is not using the user's keyboard layout by default...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants