AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Easy Unicode functions

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Sat May 30, 2009 2:57 am    Post subject: Easy Unicode functions Reply with quote

I "discovered" a really easy way to send (paste) Unicode characters from your script. I don't think I've seen this suggested on the forum before, but it's so simple I'm not sure why not. It says right in the manual, that Transform, Unicode accepts literal UTF-8 strings, so all you have to do is save your script in that format and you can embed any character in your script in human-readable form.

Code:
;IMPORTANT, you must save this script as UTF-8 to make it work.

::!?::
::?!::
PutUni("‽")
Return

::neko::
PutUni("猫")
Return

:?:damn::
PutUni("✩☠#‼")
return

;Paste UTF8 string (Hex encoded or not) as unicode.
;If you don't use Hex encoding, you must save your script as UTF8
PutUni(DataIn)
{
   SavedClip := ClipBoardAll
   ClipBoard =
   If RegExMatch(DataIn, "^[0-9a-fA-F]+$")
   {
      Loop % StrLen(DataIn) / 2
         UTF8Code .= Chr("0x" . SubStr(DataIn, A_Index * 2 - 1, 2))
   }
   Else
      UTF8Code := DataIn
   Transform, ClipBoard, Unicode, %UTF8Code%
   Send ^v
   Sleep 100 ;Generous, less wait or none will often work.
   ClipBoard := SavedClip
   return
}

There is one little catch though. If you save your script in UTF-8, all special characters need to be passed through this function. You can't do something like this anymore:
Code:
::(r)::®

You'd have to do this:
Code:
::(r)::
PutUni("®")
Return


See also: AutoHotkey_L version.


Last edited by ManaUser on Tue Jun 02, 2009 11:37 pm; edited 2 times in total
Back to top
View user's profile Send private message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sat May 30, 2009 8:40 am    Post subject: Reply with quote

Works great. One question, what text editor do you use? Both PSPad and Notepad2 don't show the characters correctly (but they are pasted fine). In my browser, I see them correctly though.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Sat May 30, 2009 4:28 pm    Post subject: Reply with quote

animeaime wrote:
Works great. One question, what text editor do you use? Both PSPad and Notepad2 don't show the characters correctly (but they are pasted fine). In my browser, I see them correctly though.

You're right about that, it doesn't depend on the editor so much as the font though. Any editor that supports UTF-8 should work, but many fonts don't have very complete unicode support.
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Sat May 30, 2009 8:59 pm    Post subject: Reply with quote

Just to let you know, AutoHotkey_L (Lexikos' build) supports sending of unicode characters through
Code:
Send, {U+XXXX}
where XXXX is the 4-digit hex code to the character.
Back to top
View user's profile Send private message AIM Address
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Sun May 31, 2009 1:19 am    Post subject: Reply with quote

Krogdor wrote:
Just to let you know, AutoHotkey_L (Lexikos' build) supports sending of unicode characters through
Code:
Send, {U+XXXX}
where XXXX is the 4-digit hex code to the character.

That's fine, but you need to look up the U+XXXX that way. This way you can just put in the literal characters, and saving in UTF-8 takes care of the rest. Of course I'm not claiming this is the be-all and end-all of Unicode methods, but it is easy, like I said in the subject.
Back to top
View user's profile Send private message
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Mon Jun 01, 2009 12:35 am    Post subject: Reply with quote

I thought I'd try making another function with the same premise, only using AutoHotkey_L's Send {U+XXXX} feature.
Code:
;IMPORTANT, you must save this script as UTF-8 to make it work.
;IMPORTANT, this script requires AutoHotkey_L

F1::SendUTF8("Смотри я отправки текста на русском языке!", 1)
F2::SendUTF8("^fΩ") ;Find an Omega

SendUTF8(Data, Raw = 0)
{
   SaveFormat := A_FormatInteger
   SetFormat IntegerFast, H
   Loop Parse, Data
   {
      If (BytesLeft > 0)
      {
         CodePoint := (CodePoint << 6) + (Asc(A_LoopField) & 63)
         If (--BytesLeft = 0)
            OutPut .= "{U+" SubStr(CodePoint, 3) "}"
      }
      Else
      {
         If Asc(A_LoopField) < 192
            If (Raw AND InStr("!#+^{}", A_LoopField))
               OutPut .= "{" A_LoopField "}"
            Else
               OutPut .= A_LoopField
         Else If Asc(A_LoopField) < 224
            CodePoint := Asc(A_LoopField) & 31, BytesLeft := 1
         Else If Asc(A_LoopField) < 240
            CodePoint := Asc(A_LoopField) & 15, BytesLeft := 2
         Else
            CodePoint := Asc(A_LoopField) & 7, BytesLeft := 3
      }
   }
   Send %OutPut%
   SetFormat IntegerFast, %SaveFormat%
}
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Sep 14, 2009 5:51 am    Post subject: Reply with quote

You ROCK
God bless you talented friend
I pray for your long life and Good health!!

this is the unicode solution that i needed Very Happy
Back to top
majkinetor



Joined: 24 May 2006
Posts: 4250
Location: Belgrade

PostPosted: Mon Sep 14, 2009 10:36 am    Post subject: Reply with quote

ManaUser solution rocks. Messing with clipboard is never good. I use CLCL to record every clipboard change.
_________________
Back to top
View user's profile Send private message
losang
Guest





PostPosted: Thu Oct 08, 2009 6:04 am    Post subject: great Reply with quote

thanks Manauser! been searching high and low for this solution!
Back to top
! 4rtist.com#&#9472;&



Joined: 04 Nov 2009
Posts: 1

PostPosted: Wed Nov 04, 2009 1:56 am    Post subject: Reply with quote

6REAT scipt

is there a way out to set up linebrakes?

`r doesnt work

﴾͡๏̯͡๏﴿
_________________
htt://4rtist.com#───█
http://﴾͡๏̯͡๏﴿.tk#_+_̯﴾͡●̯͡●﴿.tk
Back to top
View user's profile Send private message
Montu



Joined: 11 Feb 2009
Posts: 142
Location: India

PostPosted: Thu Dec 10, 2009 5:56 pm    Post subject: Reply with quote

forget all this
simply use the newly built UNICODE version of AutoHotkey
Back to top
View user's profile Send private message
unknowingly



Joined: 21 Nov 2009
Posts: 63

PostPosted: Tue Feb 16, 2010 8:19 am    Post subject: Reply with quote

Hey manauser,
(the clipboard version works for me, however only sometimes, other times i have to reload the script - it is very buggy for me)
thanks for your version - just wondering though, it doesn't work for me, instead it just replaces my hotstring with nothing.
I am running windows 7 ultimate x64.
Cheers
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group