Question

Here's a snippet of a script of mine attempting to put extra Unicode awesomeness at my fingertips.

::\iff::
    SendUnicode("⇔")
    return

; many rules later...

SendUnicode(char){
    ClipSaved := ClipboardAll ;;;
    ;apparently this is the only way AHK can handle Unicode.
    Transform, Clipboard, Unicode, %char%
    SendInput ^v
    Clipboard := ClipSaved ;;;
    return
}

Unfortunately, I had to comment out the lines marked with ;;; because they gave inconsistent results in preserving clipboard contents. The most frequent issue I experienced, specifically, is the pasting of the existing clipboard contents instead of char.

Any ideas on why the above fails and remedies I could take to fix the issue?

Was it helpful?

Solution

On Windows, the clipboard can hold different kinds of data. When you paste, the application checks which types of data are available and requests one or more types, then decides how to use it. If there is already data on the clipboard, and AutoHotkey adds unicode to the clipboard without clearing it, then the application might see and request the other data instead of the unicode.

These are the standard clipboard formats available on Windows: http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx

It's possible Autohotkey is pasting with the CF_UNICODE format and the application is requesting stale CF_TEXT data.

You should be able to use the Send function of Autohotkey_L to bypass the clipboard requirement. http://www.autohotkey.net/~Lexikos/AutoHotkey_L/

Try the code in this forum post with Autohotkey_L: http://www.autohotkey.com/forum/viewtopic.php?p=272379#272379

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top