AltGr key not getting sent to Ubuntu

Discussions related to using VirtualBox on Windows hosts.
Post Reply
sTeamTraen
Posts: 8
Joined: 1. Feb 2021, 00:56

AltGr key not getting sent to Ubuntu

Post by sTeamTraen »

I am running Ubunto 20.10 in a VirtualBox 6.1.16r140961 on Windows 10 build 19041.746.

My keyboard is a Canadian Multilingual Standard (Wikipedia: CSA_keyboard --- sorry, this is my first post so I can't include URLs), which needs the AltGr key to produce a number of characters that are common in the Unix environment, including | and ~ .

However, the AltGr key does not seem to get transmitted to the virtual machine, either as a keypress in its own right or as (AltGr + another key). For example, if I run xev in Ubuntu, I can hammer on this key as much as I like, but nothing happens. (Well, more or less nothing. Very occasionally, it works once or twice just after I start xev, but then not again. I haven't been able to work out what causes that; for all practical purposes AltGr doesn't work at all.) I have tried both with and without the "Auto Capture Keyboard" checkbox set in File/Preferences/Input, but to no avail.

I wonder if this might be related to another oddity with the keyboard. The Host key (right control) is only seen within the VM if the Windows keyboard is set to UK or US (I toggle between those and CSA within Windows). That is, if Windows has the CSA keyboard selected, the right control key is not transmitted to the VM. (The AltGr problem appears to be independent of the Windows keyboard configuration, but I'm still wondering if Windows isn't involved in some way.)

I have found a number of somewhat similar problem reports via Google, most of them quite old, but they mostly claim to have been fixed by unchecking the "Auto Capture Keyboard" box, which doesn't work for me. Another problem for somebody was that AltGr had been defined as the Compose key in gnome-tweaks, but that's not the case for me either.

Any ideas that anyone might have would be welcome.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: AltGr key not getting sent to Ubuntu

Post by fth0 »

Use the Keyboard Event Viewer webpage on the host and in the guest to investigate further (note that depending on the OS, some modifier keys will move the focus away from the text input box ;)). Additionally, you can use the 1.18 Soft Keyboard to check if the problem is inside the guest or not. Let us know (and see) what you discover.
sTeamTraen
Posts: 8
Joined: 1. Feb 2021, 00:56

Re: AltGr key not getting sent to Ubuntu

Post by sTeamTraen »

fth0 wrote:Use the Keyboard Event Viewer webpage on the host and in the guest to investigate further (note that depending on the OS, some modifier keys will move the focus away from the text input box ;)). Additionally, you can use the 1.18 Soft Keyboard to check if the problem is inside the guest or not. Let us know (and see) what you discover.
Keyboard Event Viewer on the host: works fine.

Soft Keyboard: works fine. I hit right-Alt in the US layout (or AltGr, in US-International) and whatever other key I want, and I get the CSA character reliably. For example, AltGr plus the key to the left of 1 (`~ on a US keyboard) gives me | correctly.

Where it gets interesting is with Keyboard Event Viewer in the guest (the Ubuntu VM). It doesn't work until I toggle the checkbox for File/Preferences/Input/Auto Capture Keyboard in VM VirtualBox Manager. When I do that --- whether I check or uncheck the box --- the next character that I type with AltGr in the guest works correctly; then all subsequent AltGr combinations fail (they act as if AltGr was not being pressed). Sometimes it works for the first two characters rather than just the first one, but in general it works for exactly one.

See this screen shot. I hit AltGr+(key to the left of 1) twice in succession. Numbered lines 1 through 6 are from the first press, 7 through 10 are from the second.
key-event-viewer-guest.png
key-event-viewer-guest.png (127.58 KiB) Viewed 4745 times
sTeamTraen
Posts: 8
Joined: 1. Feb 2021, 00:56

Re: AltGr key not getting sent to Ubuntu

Post by sTeamTraen »

More: I can also get it to work in the guest if I click on a couple of other Windows applications (bringing them to the foreground) and then go back into the Keyboard Event Viewer. But again it only works for the first one or (occasionally) two AltGr keypresses. Plus this version does not seem to work if the File/Preferences/Input/Auto Capture Keyboard checkbox is cleared. It has to be set. (Maybe I need to try that a bit more, though. It occurs to me that the toggling of this checkbox, which I described in my previous post, also involves bringing another Windows application, i.e. VM VirtualBox Manager, to the foreground.)
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: AltGr key not getting sent to Ubuntu

Post by fth0 »

Wow, the CSA keyboard is impressive, with up to 5 characters per key. Ok, I have some further ideas to try:

If I understand the CSA keyboard correctly, the RCtrl key serves as a kind of compose key. Therefore, I'd suggest to move the VirtualBox host key away: For example, I have defined LCtrl+LWin+LAlt as my host key, because I don't need this modifier key combination for anything else. Try if the problem persists.

Toggling Auto Capture Keyboard playing a role, could indicate that something inside the VirtualBox keyboard driver/device layers is reset and looses an unwanted state. To get additional internal information, start the VM from within a Windows cmd shell with the following commands (modify as needed):

Code: Select all

# Keyboard logging
set VBOX_RELEASE_LOG="+DEV_KBD=~0+USB_KBD=~0"
"C:\Program Files\Oracle\VirtualBox\VirtualBoxVM" --startvm "VM name"
When experimenting, write down any key combination you type, and let a few seconds pass between key combinations, to make it easier to later match the log messages in the VBox.log file. Also, I'd suggest to use a key (e.g. the 'E' key) that is independent of the keyboard layout, to avoid potential problems caused by different keyboard layouts.
sTeamTraen
Posts: 8
Joined: 1. Feb 2021, 00:56

Re: AltGr key not getting sent to Ubuntu

Post by sTeamTraen »

fth0 wrote:If I understand the CSA keyboard correctly, the RCtrl key serves as a kind of compose key. Therefore, I'd suggest to move the VirtualBox host key away: For example, I have defined LCtrl+LWin+LAlt as my host key, because I don't need this modifier key combination for anything else. Try if the problem persists.
Yes! This fixed it. Since I hardly use the host key, it doesn't matter that it's now something a bit weird. Thanks for your help!
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: AltGr key not getting sent to Ubuntu

Post by fth0 »

You're welcome. And thanks for reporting back!
sTeamTraen
Posts: 8
Joined: 1. Feb 2021, 00:56

Re: AltGr key not getting sent to Ubuntu

Post by sTeamTraen »

Something else I discovered in the course of this. I had always wondered why the display of the Host key in the bottom right of the VB window was in French (and uppercase): "CTRL DROITE". I had put it down to having first download VB Manager when I was living in France. But the other day, just once, I saw "Right Ctrl" (in title case). Then it disappeared again. But today I discovered why. It depends on the Windows keyboard layout. VB Manager considers the CSA keyboard to be in the "French" family (as, to be fair, does Ubuntu), so it shows French names for the keys. When I flip Windows to a UK keyboard before starting VB Manager I get "Right Ctrl" (or, now, "Left Windows + CTRL + ALT" --- not sure why CTRL is in uppercase though!)
sTeamTraen
Posts: 8
Joined: 1. Feb 2021, 00:56

Re: AltGr key not getting sent to Ubuntu

Post by sTeamTraen »

I'm bumping this thread to report a change that has appeared since I upgraded to Ubuntu 21(.04).

Now, I get the same problem as before if my host key combination is Left Windows + Alt + Ctrl. The AltGr key is only sent to the VM once or twice.

Some permuting reveals that the problem is with Alt (with or without Left Windows or [left] Ctrl). That is, in this version, something about Alt is not being distinguished from AltGr, in a way that it was (unless I was hallucinating back in February, when the problem seemed to be fixed) with Ubuntu 20.10.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: AltGr key not getting sent to Ubuntu

Post by fth0 »

If you only replaced the guest OS, I'd initially assume that the different behavior also originates there. You know how to investigate further. Let us know what you discover.
Post Reply