Notes about Migrating from Qwerty to Dvorak

By Yong-Siang Shih / Fri 12 July 2013 / In categories Notes

dvorak, linux, qwerty, windows

Translations: ZH

Keyboard

Windows

Newer versions of Windows could use different keyboard layouts for the login screen. Just choose it when installing or add the relevant input method in language settings.

Linux

Newer versions of Linux distributions also support dvorak layout when installing.

If you want to set the layout temporarily, you could also use the following commands:

setxkbmap dvorak # change to dvorak
setxkbmap us     # change back to qwerty

Xrdp

If you are using rdp to connect to remote linux servers, the keyboard layout is controlled by a separate configuration file. The file is located in /etc/xrdp/km-****.ini, where **** is the language suffix.

If you are able to login the server locally while not using rdp. You could use the following command to generate key map when you are using dvorak.

xrdp-genkeymap km-now.ini

Afterwards, we could use this generated file to replace the settings.

sudo mv km-now.ini /etc/xrdp/km-0409.ini

Of course, you may want to backup the file before you run the above command.

sudo mv /etc/xrdp/km-0409.ini /etc/xrdp/km-0409.ini.old

Restart the xrdp server to load the configuration.

sudo /etc/init.d/xrdp restart

However, if you are unable to login locally, you would not be able to generate the correct file because you are unable to change keyboard layout to dvorak. So I created a Python script to convert km-0409.ini to dvorak settings.

#!/usr/bin/env python3
# xrdpkeymap_qwerty_to_dvorak.py
"""
Usage: python xrdpkeymap_qwerty_to_dvorak.py km-input.ini > km-output.ini
"""
import fileinput
import re

# keycodes
# $ xmodmap -pk for current mapping
# ref: http://forums.fedoraforum.org/showthread.php?t=265100
QWERTY = (20, 21, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 38, 39, 40,
          41, 42, 43, 44, 45, 46, 47, 48, 52, 53, 54, 55, 56, 57, 58, 59, 60,
          61)

DVORAK = (34, 35, 48, 59, 60, 33, 29, 41, 42, 54, 27, 46, 61, 21, 38, 32, 26,
          30, 31, 40, 43, 28, 57, 39, 20, 47, 24, 44, 45, 53, 56, 58, 25, 55,
          52)

TRANS_DICT = dict(list(zip(QWERTY, DVORAK)))


def main():
    re_title = re.compile(r'\[.*\]\n')
    re_keydef = re.compile(r'Key(\d+)=(.*)\n')
    buf = []
    buf_dict = {}

    def output_keydefs():
        for k in buf:
            if k in TRANS_DICT:
                print('Key%d=%s' % (k, buf_dict[TRANS_DICT[k]]))
            else:
                print('Key%d=%s' % (k, buf_dict[k]))
        return [], {}

    for line in fileinput.input():
        if re_title.match(line) is not None:
            buf, buf_dict = output_keydefs()
            print(line, end='')
        elif re_keydef.match(line) is not None:
            m = re_keydef.match(line)
            buf.append(int(m.group(1)))
            buf_dict[int(m.group(1))] = m.group(2)
        else:
            print(line, end='')

    # output remaining keys
    output_keydefs()


if __name__ == '__main__':
    main()

Vim

Sometimes we cannot even restart xrdp server. We may try to use the following commands in Vim. This enables us to use dvorak at least in Vim.

set keymap=dvorak
set langmap=-=qwertyuiop[]sdfghjkl\\;'zxcvbn\\,./_+QWERTYUIOP{}SDFGHJKL:\"ZXCVBN<>?;[]'\\,.pyfgcrl/=oeuidhtns-\\;qjkxbwvz{}\"<>PYFGCRL?+OEUIDHTNS_:QJKXBWVZ

Download

Refer to shaform/dvorak-tools for all script files.

Yong-Siang Shih

Author

Yong-Siang Shih

Software Engineer, Machine Learning Scientist, Open Source Enthusiast. Worked at Appier building machine learning systems, and interned at Google, IBM, and Microsoft as software engineering intern. Love to learn and build things.* Follow me on GitHub

Load Disqus Comments