Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An alternative way to input unicode characters with Autokey

An alternative way to input unicode characters with Autokey

The post Add any symbol without leaving the keyboard explains how to input unicode characters easily on Linux. However, the instructions given may not always work or you may be stuck with Autokey version 2, which doesn't play nice with unicode. What follows is a brief description of a work-around.

First, create a file called containing the following

import sys

from subprocess import Popen, PIPE

def paste_char(symbol):
    c = Popen(['xclip', '-selection', 'clipboard'], stdin=PIPE)
    p = Popen(['autokey-run', '-s', 'Paste'])

This script (1) ensures the correct encoding is being used so that unicode works correctly, (2) copies a given symbol to the clipboard, and (3) pastes it. The script uses xclip, which is probably installed by default, but may need to be installed.

In Autokey, go to Edit > Preferences > Script Engine. Ensure the User Module Folder points to the directory containing

Then, create a script called 'Paste'. As implied above, this is called by name by The Paste script simply executes a paste command, which is typically Ctrl+V, but for some applications, it may differ. For me, Paste looks like

window_title = window.get_active_title()
if 'Sublime Text (UNREGISTERED)' in window_title:
elif 'IPython' == window.get_active_title():
elif 'Terminal' == window.get_active_title():
elif 'Matlab console' == window.get_active_title():

It should be self-explanatory how to adjust this to your case.

We're now ready to set up a script to paste a unicode character. Let's use Δ as an example.

Click File > New > Script. Name it Delta. Then paste the following two lines

from MyCopy import paste_char

Finally, set up an abbreviation that calls the Delta script. I personally prefer '/Delta', but you can use whatever you like.


This comment has been minimized.

Copy link

camilovietnam commented Oct 14, 2019

Brilliant! Worked perfectly, the only thing I had to do was install xclip. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.