I found the solution to be to create the following aliases in my .bashrc
file:
alias asdf="sudo loadkeys dvorak"
alias aoeu="sudo loadkeys us"
Now, when I find myself with the wrong layout, I type the same four keys on the home row to switch layouts.
The only issue I had with this was that it could be difficult to enter a password for the sudo
command when the wrong layout is enabled. There are two solutions to this problem, but they may be a security issue in some environments:
Use a strong-ish password comprised only of numbers, symbols, and the letters M and A (they're the same for both Dvorak and Qwerty).
Set the suid
bit on /usr/bin/loadkeys
so it automatically runs as root (and you don't need to run it with sudo
). I used the command sudo chmod u+s /usr/bin/loadkeys
. Note: I needed to install the console-data
package beforehand.
Edit: added excellent suid
suggestion from ssmy.