Shift key gets stuck, pressing ctrl also presses shift, on VirtualBox on macOS Host

VirtualBox has been working fine for me all week.

Today I just updated to the latest version.

Then I was unable to log-in for a long time and couldn’t figure out why.

Eventually I figured out that pressing either shift key causes the VirtualBox to register the shift key as being held down. All subsequent keystrokes sent are accompanied by shift (a -> A, 4 -> $)

Unfocusing the VirtualBox window (switching back to macOS) and then refocusing the VirtualBox window resets the shift key.

Additionally, I have noticed that ctrl cannot be sent: every ctrl keystroke gets registered by the VM as ctrl + shift; after pressing ctrl all subsequent keys are “uppercased”, and also ctrl + c never interrupts programs in terminal. I only ever have to press ctrl + c, ctrl + v to copy/paste, regardless of the shift key’s status due to the other bug.

These are the only two—probably related—bugs that I’ve found so far, but there may be more.

Since noticing these problems, I’ve tried deleting VirtualBox.app from my Applications folder and then installing older versions of VirtualBox from virtualbox.org, but the problem doesn’t go away in 6.0.x builds and 5.2.x builds can’t run my VM.

How can I fix the keyboard’s behaviour?