| View previous topic :: View next topic |
| Author |
Message |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sat May 30, 2009 1:57 am Post subject: Easy Unicode functions |
|
|
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:
You'd have to do this:
| Code: | ::(r)::
PutUni("®")
Return |
See also: AutoHotkey_L version.
Last edited by ManaUser on Tue Jun 02, 2009 10:37 pm; edited 2 times in total |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Sat May 30, 2009 7:40 am Post subject: |
|
|
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 |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sat May 30, 2009 3:28 pm Post subject: |
|
|
| 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 |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Sat May 30, 2009 7:59 pm Post subject: |
|
|
| Just to let you know, AutoHotkey_L (Lexikos' build) supports sending of unicode characters through where XXXX is the 4-digit hex code to the character. |
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sun May 31, 2009 12:19 am Post subject: |
|
|
| Krogdor wrote: | | Just to let you know, AutoHotkey_L (Lexikos' build) supports sending of unicode characters through 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 |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Sun May 31, 2009 11:35 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Mon Sep 14, 2009 4:51 am Post subject: |
|
|
You ROCK
God bless you talented friend
I pray for your long life and Good health!!
this is the unicode solution that i needed  |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Mon Sep 14, 2009 9:36 am Post subject: |
|
|
ManaUser solution rocks. Messing with clipboard is never good. I use CLCL to record every clipboard change. _________________
 |
|
| Back to top |
|
 |
losang Guest
|
Posted: Thu Oct 08, 2009 5:04 am Post subject: great |
|
|
| thanks Manauser! been searching high and low for this solution! |
|
| Back to top |
|
 |
! 4rtist.com#─&
Joined: 04 Nov 2009 Posts: 1
|
|
| Back to top |
|
 |
Montu
Joined: 11 Feb 2009 Posts: 142 Location: India
|
|
| Back to top |
|
 |
unknowingly
Joined: 21 Nov 2009 Posts: 63
|
Posted: Tue Feb 16, 2010 7:19 am Post subject: |
|
|
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 |
|
 |
Maxime Boisset Guest
|
Posted: Mon Mar 14, 2011 11:34 am Post subject: Type Unicode characters using autoreplace |
|
|
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 á and to write a rightwards arrow (→) you type ,-> or &rarr. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Oct 26, 2011 10:22 pm Post subject: Re: Type Unicode characters using autoreplace |
|
|
| Quote: | | For example, to write á, you type ,'a or á 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 |
|
| Back to top |
|
 |
|