Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Function for sending Unicode text


  • Please log in to reply
8 replies to this topic
ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
This is a simple function that makes sending unicode text easier. I thought it would be particularly helpful for hotkeys and hotstrings. It uses the Transform, , Unicode command, and then further encodes it as hexidecimal. Select your Unicode text and press F12 to copy hex code for your text, than use PutUni("<your hex code>") in your script to send it.

#SingleInstance Force
#NoEnv

SetFormat Integer, H

F8::PutUni(ClipBoard)

;Sample Hotkeys
F9::PutUni("416365206f6620e299a0") ;Ace of (Spades)
F10::PutUni("e280bd") ; Interrobang
F11::PutUni("c5a1c491c48dc487c5be") ;Croatian letters, resembles "sdccz"

;Sample Hotstrings
:?:damn::
PutUni("e29ca9e298a023e280bc") ;cartoon style curse
return

::spam::
PutUni("e382b9e38391e383a0") ; Japanese for spam (per Bablefish)
return

;Copy unicode in correct format for PutUni.
F12::
ClipBoard =
Send ^c
ClipWait 0
Transform, OutputVar, Unicode
ClipBoard =
Loop % StrLen(OutputVar)
   ClipBoard .= SubStr(Asc(SubStr(OutputVar, A_Index, 1)), 3)
Return

;Paste hex string as unicode.
[color=red];This is the only part you need to add to your script to use PutUni.
PutUni(HexIn)
{
   SavedClip := ClipBoardAll
   Loop % StrLen(HexIn) / 2
      TransCode .= Chr("0x" . SubStr(HexIn, A_Index * 2 - 1, 2))
   Transform, ClipBoard, Unicode, %TransCode%
   Send ^v
   Sleep 100 ;Generous, less wait or none will often work.
   ClipBoard := SavedClip
   return
}[/color]
Note, some of the examples may not work, depending on on what characters are supported where you use it. Web browsers generally have good unicode support.

This version is obsolete: Use this one.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This can be alternative to the dll call to the Windows Unicode send-input function Shimanov found earlier. His approach has the advantage that the clipboard is not touched at sending, so there is no need to save/restore it, and it works faster. But this script does not use a dll, what can be an advantage in some cases.

rousni
  • Members
  • 133 posts
  • Last active: Jul 17 2018 01:36 PM
  • Joined: 23 Mar 2006

the Windows Unicode send-input function Shimanov found earlier


I tried vainly to find this function in the forum. Could you specify a link? Thanks

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I tried vainly to find this function in the forum.


Really ?! :roll:
The keyword is Unicode and author is shimanov
You get only one result for that ( as of today ).

Anyways! <!-- m -->http://www.autohotke...opic.php?t=7328<!-- m -->

:)

  • Guests
  • Last active:
  • Joined: --
http://www.autohotke.../topic7328.html

Guest2
  • Guests
  • Last active:
  • Joined: --
Thanks! I've been looking on how to do this for the longest time, and it seems that the code in the AutoHotKey help file did not help me. Thanks a bunch! You're a genius!

deleteme
  • Members
  • 3 posts
  • Last active: May 22 2015 12:17 PM
  • Joined: 18 Oct 2007
Thank you for your help. I tried the code and get good results when copying codes from your script, but unicode codes you use don't match with ones found on unicode.org.

For instance code for š on unicode.org is "0161" while you (successfully) use "c5a1". I just realised these could be one and same but I am not literate with number format conversions - is there a page with codes you use charted?

regs
del

MateFARKAS
  • Members
  • 75 posts
  • Last active: Apr 01 2013 06:38 PM
  • Joined: 28 Oct 2007
Try the Extended SendU function

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007

Thank you for your help. I tried the code and get good results when copying codes from your script, but unicode codes you use don't match with ones found on unicode.org.

For instance code for š on unicode.org is "0161" while you (successfully) use "c5a1". I just realised these could be one and same but I am not literate with number format conversions - is there a page with codes you use charted?

regs
del

It uses AutoHotkey's built in Transform command, which is based on UTF-8 encounting, and then converts it to hexadecimal. Here's a site with list of UTF-8 codes:
<!-- m -->http://www.utf8-char...e-utf8-table.pl<!-- m -->
Just remove the space. Or you could add this to UniPut so it tolerates the space:
PutUni(HexIn)
{
   SavedClip := ClipBoardAll
   [color=red]StringReplace HexIn, HexIn, %A_Space%,, All[/color]
   Loop % StrLen(HexIn) / 2
      TransCode .= Chr("0x" . SubStr(HexIn, A_Index * 2 - 1, 2))
   Transform, ClipBoard, Unicode, %TransCode%
   Send ^v
   Sleep 100 ;Generous, less wait or none will often work.
   ClipBoard := SavedClip
   return
}