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

Missing key with german keyboard on MacBook Pro M2 using Apple Virtualization framework #5037

Open
msander opened this issue Feb 18, 2023 · 16 comments
Labels
apple virtualization macOS Virtualization issues

Comments

@msander
Copy link

msander commented Feb 18, 2023

I am convinced, this is not a guest linux keymap problem

Describe the issue

  • The "^°" key (left besides "1") does not work using Apple virtualization framework
  • The "<>" key (next to left shift) outputs "^°".
  • All other keys work correctly.
  • Using qemu everything works correctly

Configuration

  • UTM Version: 4.1.5
  • macOS Version: 13.2.1
  • Mac Chip (Intel, M1, ...): M2 Max

Debug log
How to activate for Apple Virtualization?

Screenshots
photo_keyboard

screenshot_xev

@ferdiga
Copy link

ferdiga commented Feb 18, 2023

I use UTM with DEBIAN 11 (LDXE) on a Macbook M1 with german Keyboard and 16GB memory
I have to confirm various reports - extremely fast and low memory consumption.

I wish the following command would be incorporated in the Config GUI (or I didn't find it) and/or be part of the installation procedure.

login as root:
dpkg-reconfigure keyboard-configuration
I choose
Apple-Laptop
Deutsch-Macintosh
kein AltGr
keine Compose
Strg-Alt-Zurück - Nein


The "^" key - I have to press the key twice
The "<>" key - work

@ferdiga
Copy link

ferdiga commented Feb 18, 2023

unfortunately the above setting does not provide for @ and ~
any ideas?

@ferdiga
Copy link

ferdiga commented Feb 18, 2023

I modified the configuration (in english now)
dpkg-reconfigure keyboard-configuration
I choose

Apple
German
right AltGr
no compose key
Strg-Alt-Zurück - No

"hidden" characters
@ Option right + q
~ Option right + (+*) key

@msander
Copy link
Author

msander commented Feb 18, 2023

@ferdiga The behaviour is actually the same with different keyboard-configurations. I don't think it's a guest problem, as xev does not even show a keycode for the "^°" key.

@ferdiga
Copy link

ferdiga commented Feb 18, 2023

This is the keyboard layout for the above configuration
2012-08-15_155642_german-keyboard-2620983067

@ferdiga
Copy link

ferdiga commented Feb 19, 2023

I would suggest to display the current keyboard mapping in the UTM-Help Menu - if this possible at all

@naga-re
Copy link

naga-re commented Feb 22, 2023

This is a bug in Apple's virtualization framework (probably in virtio keyboard device) affecting Macs (with Apple Silicon chips but probably also MacIntel machines) with a physical keyboard that have an ISO mapping (like French Azerty keyboard , German keyboard, Danish keyboard, etc.). The framework bug transforms the ISO mapping into ANSI mapping (that of American Qwerty keyboards) with these problems of keys missing or not in their place :

For example (for French Azerty Keyboard), the code for the @ key on an ISO keyboard is 0Ah, but the code for this key on an ANSI keyboard is 32h (which is the code for the extra key < in ISO).

The problem concerns both MacOS VMs and Linux VMs and the integrated keyboards of MacBook (Pro) as well as separate keyboards (like Apple Magic Keyboard, etc.). It concerns all software that uses this framework, UTM included.
This bug has existed since the first Beta of Ventura.
I reported this bug to Apple as early as August 2022. Apple asked me for clarification in early January 2023 to learn more and reproduce it. I haven't had any news since (Apple Feedback number : 11489872)

The ideal is that Apple fixes this bug.
This bug can be temporarily fixed with Karabiner app by remapping the affected keys.
In the worst case, UTM would have to patch this by offering key remapping when an ISO keyboard is used.

@ferdiga
Copy link

ferdiga commented Feb 22, 2023

well it would already be helpful if during the installation the command
dpkg-reconfigure keyboard-configuration
would be executed or a hint would be given.

@martin-braun
Copy link

martin-braun commented May 22, 2023

The ^/< swap is a common problem with German keyboards when being in QEMU with a MacOS host and it affects T2 Intel Macs as well. It's not just a problem of UTM, also when remote controlling VMs/LXCs in proxmox. I use Karabiner to swap those events and turn my deadkeylocks into nodeadkeys, so when I press ^ in any Terminals (incl. QEMU sessions) I will not have to press space afterwards to trigger it (nice for vim).

Here is a sample how it can look:

                    {
                        "description": "'^' <-> '<', nodeadkeys @ QEMU",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.utmapp\\.UTM$",
                                            "^com\\.electron\\.nativefier\\.proxmox-"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "non_us_backslash",
                                    "modifiers": {
                                        "optional": [
                                            "left_shift",
                                            "right_shift",
                                            "caps_lock"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "grave_accent_and_tilde"
                                    },
                                    {
                                        "key_code": "spacebar"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.utmapp\\.UTM$",
                                            "^com\\.electron\\.nativefier\\.proxmox-"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "grave_accent_and_tilde",
                                    "modifiers": {
                                        "optional": [
                                            "left_shift",
                                            "right_shift",
                                            "caps_lock"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "non_us_backslash"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.utmapp\\.UTM$",
                                            "^com\\.electron\\.nativefier\\.proxmox-"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "equal_sign"
                                },
                                "to": [
                                    {
                                        "key_code": "equal_sign"
                                    },
                                    {
                                        "key_code": "spacebar"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.utmapp\\.UTM$",
                                            "^com\\.electron\\.nativefier\\.proxmox-"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "equal_sign",
                                    "modifiers": {
                                        "mandatory": [
                                            "shift"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "equal_sign",
                                        "modifiers": "left_shift"
                                    },
                                    {
                                        "key_code": "spacebar"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.apple\\.terminal$",
                                            "^com\\.googlecode\\.iterm2$",
                                            "^com\\.google\\.android\\.studio$"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "n",
                                    "modifiers": {
                                        "mandatory": [
                                            "option"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "n",
                                        "modifiers": "left_option"
                                    },
                                    {
                                        "key_code": "spacebar"
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    },

To get the other stuff that I expect from a Mac keyboard in Windows, I install Microsoft.PowerToys via winget and setup the keyboard manager to re-map all my stuff properly, so I get the most important mappings like []{}@~|\ like I'm used to.

I guess the very right move would be to do it like Parallels with a kbdEdit keyboard layout for Mac keyboards, but my method is also portable, since PowerToys supports to export/import settings. Couldn't find the kbdEdit image from a trustworthy source and I needed something quick.

Hope this helps.

@naga-re
Copy link

naga-re commented Jun 8, 2023

Among the new features of apple's virtualization framework for MacOS Sonoma, I see that a new class has appeared:

VZMacKeyboardConfiguration

Perhaps a solution to our ISO keyboard problems and better management of Mac keyboards?
Even if it's too early (we're only in the first beta of Sonoma), are the UTM teams planning to integrate these new features in a future version of UTM?

@naga-re
Copy link

naga-re commented Jun 25, 2023

The problem ultimately remains with Sonoma (Beta 2).
If the support of the function keys and controls of the Mac are appreciable (globe key, sound, multimedia, etc.), the bug of the bad mapping of the ISO keyboards (French, Danish, German, etc.) is unfortunately not always not corrected, while the keyboard works perfectly on the beta directly installed on a Mac, without going through a VM.

Explanation and solution of this bug:

The code for the @ key on a French ISO keyboard is 0Ah, but the code for this key on an ANSI keyboard is 32h (which is the code for the extra key < in ISO). That explains why I don't see the @. It's on the code key 0Ah which does not exist.

The virtualization framework does, for some reason that I cannot explain, this code replacement for the keys, taking into account neither the settings of the keyboard of the host machine, nor the settings of the keyboard of the virtual machine.

@naga-re
Copy link

naga-re commented Jun 27, 2023

Howard Oakley, from the excellent site The Eclecticlight Company has just published a post on this problem and made a bug report to Apple:

https://eclecticlight.co/2023/06/27/keyboard-layouts-in-lightweight-virtualisation/

@cdavidc
Copy link

cdavidc commented Feb 6, 2024

For people using French Azerty Keyboards in macOS VMs, here is the rule I am using in Karabiner (add it to the "rules" section of your "karabiner.json" file):

                    {
                        "description": "Remap '@' to 'alt-`' in UTM",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.utmapp\\.UTM$"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "non_us_backslash",
                                    "modifiers": {
                                        "optional": [
                                            "left_shift",
                                            "right_shift",
                                            "caps_lock"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "non_us_pound",
                                        "modifiers": "left_option"
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }

@theophanemayaud
Copy link

theophanemayaud commented Feb 27, 2024

Having a french keyboard I also stumbled on this problem when trying out UTM instead of Parallels (I want to see if I can build my QT app on windows x86 from my new M3 macbook and sell my old intel macbook). From the Howard Oakley article, I see that the simplest solution instead of remapping a certain combination to those characters, is to use the standard, preexisting, obscure combination for those @ and # symbols, instead of installing a separate app within the VM, understanding how to set it up, and choosing my own key combination which I didn't manage to do easily :

  • # : [option (⌥)] + [pound/back quote (£ `)]

  • @ : [option (⌥)] + [shift] + [pound/back quote (£ `)]

@RafBois
Copy link

RafBois commented May 13, 2024

Quelle galère ce clavier AZERTY

@naga-re
Copy link

naga-re commented May 14, 2024

Amazing ! There is news.

Installing the final version of macOS Sonoma 14.5 seems to have partly resolved this bug, at least with the Azerty keyboard (Apple magic keyboard for example). Keyboard mapping is good now.
However, there remains a cosmetic bug in the keyboard viewer, which continues to display a bad key layout (mixing between ISO keys on an ANSI keyboard).

The test was carried out with macOS 14.5, UTM 4.5.2 and a virtual machine updated to macOS 14.5.

On the other hand, on a Linux VM (Ubuntu 24.04) using Apple's virtualization framework, the bug is still present, but with improvement: there is only an inversion of the mapping of characters between the @ keys and < . The rest of the keyboard is now OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple virtualization macOS Virtualization issues
Projects
None yet
Development

No branches or pull requests

8 participants