AutoHotkey Community

It is currently May 26th, 2012, 11:07 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Easy Unicode functions
PostPosted: May 30th, 2009, 2:57 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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 June 2nd, 2009, 11:37 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2009, 8:40 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2009, 4:28 pm 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2009, 8:59 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2009, 1:19 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2009, 12:35 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 5:51 am 
You ROCK
God bless you talented friend
I pray for your long life and Good health!!

this is the unicode solution that i needed :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 10:36 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
ManaUser solution rocks. Messing with clipboard is never good. I use CLCL to record every clipboard change.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: great
PostPosted: October 8th, 2009, 6:04 am 
thanks Manauser! been searching high and low for this solution!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2009, 1:56 am 
Offline

Joined: November 4th, 2009, 1:45 am
Posts: 1
6REAT scipt

is there a way out to set up linebrakes?

`r doesnt work

﴾͡๏̯͡๏﴿

_________________
[url]htt://4rtist.com#───█[/url]
[url]http://﴾͡๏̯͡๏﴿.tk#_+_̯﴾͡●̯͡●﴿.tk[/url]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 5:56 pm 
Offline

Joined: February 11th, 2009, 2:23 pm
Posts: 142
Location: India
forget all this
simply use the newly built UNICODE version of AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2010, 8:19 am 
Offline

Joined: November 21st, 2009, 11:06 am
Posts: 63
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 14th, 2011, 12:34 pm 
I have made a little utility using the putuni function
http://catology.boisset.eu/Carlinga

Carlinga is a little program that helps typing special characters like oe, ß, ½, Á. It automatically replaces some character sequences, called hotstrings or mnemonics, with special characters. For example, to write á, you type ,'a or &aacute; and to write a rightwards arrow (→) you type ,-> or &rarr.


Report this post
Top
  
Reply with quote  
PostPosted: October 26th, 2011, 11:22 pm 
Quote:
For example, to write á, you type ,'a or &aacute; and to write a rightwards arrow (→) you type ,-> or &rarr.


Does anyone have an idea how the comma could be replaced by a ControlKey (eg AltGr or RWin)?

This would emulate the 'real' composing from Unix:
ComposeKey + _ + o = ō

Regards
Miguel


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], Stigg and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group