Advertisement
Guest User

Transliterate using Pause button

a guest
Jul 19th, 2013
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $~Pause::RecodeTextENRU()
  2.  
  3. RecodeTextENRU()
  4. {
  5.    StringCaseSense On
  6.    AutoTrim,Off
  7.  
  8.    clipSave:=clipAnsi()
  9.    send ^{Insert}
  10.    sleep,50
  11.  
  12.    dest=
  13.    text:=clipAnsi()
  14.    StringCaseSense,On
  15.    prevCharToEN=0
  16.    ;      АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ
  17.    RUtoEN=F<DULT:PBQRKVYJGHCNEA{WXIO}SM">Zf,dult;pbqrkvyjghcnea[wxio]sm'.z
  18.   RUtoSP1=хъжэбюХЪЖЭБЮ.,/";:?
  19.    RUtoSP2=[];',.{}:"<>/?|@#$^&
  20.    ;"       ABCDEFGHIJKLMNOPQRSTUVWXYZ
  21.    ENtoRU=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯфисвуапршолдьтщзйкыегмцчня
  22.  
  23.    loop,parse,text
  24.    {
  25.       destChar=%A_LoopField%
  26.  
  27.       ; check explicit (non punctuations) ranges
  28.       ifGreaterOrEqual,A_LoopField,А
  29.          prevCharToEN=1
  30.       else if A_LoopField between A and Z
  31.          prevCharToEN=0
  32.       else if A_LoopField between a and z
  33.          prevCharToEN=0
  34.  
  35.       ; to Russian
  36.       ifEqual,prevCharToEN,0
  37.       {   StringGetPos,i,RUtoEN,%A_LoopField%
  38.          ifEqual,ErrorLevel,0
  39.             Transform,destChar,chr,% i + 0xC0
  40.          else
  41.          {   StringGetPos,i,RUtoSP2,%A_LoopField%
  42.             ifEqual,ErrorLevel,0
  43.                StringMid,destChar,RUtoSP1,% i+1, 1
  44.          }
  45.       }
  46.  
  47.       ; to English
  48.       ifEqual,destChar,%A_LoopField%
  49.       {
  50.          StringGetPos,i,ENtoRU,%A_LoopField%
  51.          ifEqual,ErrorLevel,0
  52.             Transform,destChar,chr,% i + (i>=26 ? 71 : 65)
  53.          else ; check .,;':"[]{}
  54.          {   StringGetPos,i,RUtoSP1,%A_LoopField%
  55.             ifEqual,ErrorLevel,0,StringMid,destChar,RUtoSP2,% i+1, 1
  56.          }
  57.          ifNotEqual,destChar,%A_LoopField%
  58.             prevCharToEN=1
  59.       }
  60.       dest=%dest%%destChar%
  61.    }
  62.  
  63.    ; decide compatibility of unicode clipboard
  64.    WinGetClass,cls,A
  65.    if cls in TMsgEditor,wndclass_desked_gsk
  66.    {
  67.       ControlGetFocus,cls,A
  68.       ifInString,cls,TXTRichEdit
  69.          clipSetUnicode(dest)
  70.       else
  71.          Clipboard=%dest%
  72.    }
  73.    else
  74.       clipSetUnicode(dest)
  75.    sleep,50
  76.    send +{Insert}
  77.    sleep 50
  78.  
  79.    clipSetUnicode(clipSave)
  80.    LangSwitch()
  81. }
  82.  
  83. ; read unicode clipboard into ansi string
  84. clipAnsi()
  85. {
  86.    StringLen,L,Clipboard
  87.    L:=(L+1)*4
  88.    transform,ca_Clip,unicode
  89.    varSetCapacity(ca_WideText,L,0)
  90.    varSetCapacity(ca_AnsiText,L,0)
  91.    ; Convert UTF-8 to UTF-16.   CP_UTF8=65001
  92.    if dllCall("MultiByteToWideChar",uint,65001, uint,0, str,ca_Clip
  93.               , uint,-1, str,ca_WideText, uint,L/2)
  94.       dllCall("WideCharToMultiByte",uint,0, uint,0, str,ca_WideText
  95.               , uint,-1, str,ca_AnsiText, uint,L/2, uint,0, uint,0)
  96.       ; Convert UTF-16 to ANSI.  CP_ACP=0
  97.    return ca_AnsiText
  98. }
  99.  
  100. ;--------------------------------------------------------------
  101. ; copy ansi string to clipboard in unicode mode
  102. clipSetUnicode(cu_AnsiText)
  103. {
  104.    StringLen,L,cu_AnsiText
  105.    L:=(L+1)*4
  106.    varSetCapacity(cu_WideText,L,0)
  107.    varSetCapacity(cu_UTFtext,L,0)
  108.    ; ANSI to UTF-16.   CP_ACP=0
  109.    if dllCall("MultiByteToWideChar",uint,0, uint,0, str,cu_AnsiText
  110.               , uint,-1, str,cu_WideText, uint,L/2)
  111.       dllCall("WideCharToMultiByte",uint,65001, uint,0, str,cu_WideText
  112.               , uint,-1, str,cu_UTFtext, uint,L/2, uint,0, uint,0)
  113.       ; Convert UTF-16 to UTF-8.  CP_UTF8=65001
  114.    transform,clipboard,unicode,%cu_UTFtext%
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement