Lonnie Best Lonnie Best - 6 months ago 75
Python Question

AutoKey - clipboard.get_selection() function fails on certain strings

I've simplified my script so you can focus on the essence my problem.

In AutoKey (not AutoHotKey), I made a Hot-Key (shift-alt-T) that performs this script on any string I have highlighted (like in gedit for example -- but any other gui editor too).

strSelectedText = clipboard.get_selection()
keyboard.send_keys(" " + strSelectedText)

The script modifies the highlighted text and adds a space to the beginning of the string.

It works for most strings I highlight, but not this one:

* Copyright © 2008–2012 Lonnie Best. Licensed under the MIT License.

It works for this string:

* Add a Space 2.0.1

but not on this one:

* Add a Space 2.0.1 –

At the python command prompt, it has no problem any of those strings, yet the clipboard.get_selection() function seems to get corrupted by them.

I'm rather new to python scripting, so I'm not sure if this is an AutoKey bug, or if I'm missing some knowledge I should know about encoding/preparing strings in python.

Please help. I'm doing this on Ubuntu 12.04:

sudo apt-get install autokey-qt

Answer Source

There is no keyboard key for the copyright symbol, or any non-ASCII character like the EN DASH in your third example. Your script code would have to somehow translate any non-ASCII Unicode characters into the appropriate keyboard sequences to generate them. Perhaps you could grab from the clipboard and use a clipboard function to paste the modified string back into your App.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download