I recently had to switch provider for cloud-based Windows VMs. After firing up
the new VM and its viewer application (AWS Nice dcvviewer), I found that basic
features such as Alt-Tab and mouse forward & backward buttons didn’t work. This
was an annoying productivity drain, so I set out to solve the problem. Here’s
the story of how I fixed it using the keyd key remapping tool.
What Do These keys Do?
In case you aren’t familiar with these keyboard shortcuts, here’s a brief description of what they are and why you’d use them. Apparently even some of our IT employees had never heard of these!
- Alt-Tab
- Switches between windows or applications. Use this if you have your hands on the keyboard rather than the mouse; it’s much quicker than moving your hand back to the mouse and clicking the relevant window in the task bar!
- Mouse buttons
- Most non-cheap modern mice have forward and backward buttons in addition to the regular left and right buttons. These are useful when using a web browser or file explorer, to page through your tab history.
Early Attempts
I did a lot of research via Google searches, and found many other people had reported the same issue. Still, Amazon hasn’t fixed it for some reason. Ultimately I didn’t find any kind of complete fix, just disappointed users.
That said, someone did point out that Alt-Windows-Tab did work. I also realized
that there were keyboard shortcuts that work the same as the mouse forward &
backward buttons (Alt-Left, Alt-Right), at least in a browser and file explorer
window. Experiments with xdotool showed that the
alternative keystrokes could be injected in the dcvviewer; a path towards a fix
was appearing!
keyd to the Rescue
What I needed was a keyboard remapping tool; something that would detect when
I’d pressed a specific key, translate it to some other keycode, and send that
to the application instead. I tried a few such tools that didn’t work, but
eventually found keyd, which did! keyd isn’t packaged for Ubuntu, so I had
to install it from a PPA:
Installation
$ sudo add-apt-repository ppa:keyd-team/ppa
$ sudo apt install keyd keyd-application-mapperWe only want to send modified keycodes to the dcvviewer application, so that
local applications are not affected. keyd-application-mapper is a keyd
add-on that enables this.
Selecting Input Devices
keyd needs to be informed which input devices (keyboards, mice) to handle. To
do so, create configuration file /etc/keyd/default.conf:
[ids]
# Laptop keyboard
0001:0001
# Targus USB keyboard
0461:0010
# Logitech USB mouse
046d:c069The IDs may be found by running lsusb or /usr/bin/keyd.rvaiya monitor.
Configuring Key Remappings
keyd supports a few configuration files. keyd-application-mapper
specifically is configured via ~/.config/keyd/app.conf; create it with the
following content:
[dcvviewer]
alt.tab = M-A-tab
mouse1 = A-left
mouse2 = A-rightStarting keyd
Enable keyd to run at boot, and start/restart it now that all necessary
configuration files are in place:
systemctl enable keyd
service keyd restartArrange for /usr/bin/keyd-application-mapper -d to be run when you log in.
For debugging, you may run that command directly in a terminal. For
persistence, you might launch it from your .xsession file, or in XFCE, visit
Settings > Session and Startup > Application Autostart, and add a new entry for
this command.
Conclusion
With keyd running, I can now focus the dcvviewer window and use the
keyboard and mouse as normal. I no longer have to remember to use a completely
different set of keyboard shortcuts based on whether I’m using a local
application, or a remote Windows session via dcvviewer.
Caveats
/usr/bin/keyd-application-mapper can remap keys based on the local
application that has focus. It can’t detect which application has focus within
a remote viewer application such as dcvviewer. Thus if some Windows
application uses a different keyboard shortcut that Alt-Left for the back mouse
button, I won’t be able to solve that. Still, this is a pretty common keyboard
equivalent, so touch wood this won’t come up!