Advertisement
Guest User

Untitled

a guest
Jun 8th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Реверс всего текста неверной раскладки по левый контрол+ капслук
  2. LControl & CapsLock::
  3. {
  4.     ;hModule := DllCall("LoadLibrary", "str", "AHKHelper.dll")
  5.    
  6.     ;clipSave:=clipAnsi()
  7.     ;send ^{Insert}
  8.     ;sleep,50
  9.  
  10.    
  11.     ;text:="qwerty"
  12.     ;clipAnsi()
  13.    
  14.    
  15.    
  16.     ;Result := DllCall("AHKHelper.dll\SetDllString1", "Str", "qwert")
  17.     ;msgbox, %Result%
  18.     ;Result := DllCall("AHKHelper.dll\GetDllString1", "Str", "qwert")
  19.     ;msgbox, %Result%
  20.    
  21. ;   StrPut(strA, %Result%, 2)
  22. ;   msgbox, %strA%
  23. ;  SendInput, ^{sc01E}
  24.  
  25.  
  26.    
  27.   ;runwait, HelperForAHK_c.exe " /recodepls" ,PIDD
  28.   ;FileRead, fBuff, buf
  29.   ;msgbox, %fBuff%
  30.  
  31.  
  32.    SendInput, ^{sc01E}
  33.   LangSwitch(1)
  34.   sleep, 50
  35.   RecodeTextENRU()
  36.   Return
  37.  
  38.  
  39.   ;LangSwitch()
  40.   ;sleep, 50
  41.   ;RecodeTextENRU()
  42.   ;rec()
  43.  
  44.   ;RecodeTextENRU()
  45.  
  46. }
  47. ;реверс текста
  48.  
  49.  
  50. RecodeTextENRU()
  51. {
  52.     StringCaseSense On
  53.     AutoTrim,Off
  54.  
  55.     clipSave:=clipAnsi()
  56.     send ^{Insert}
  57.     sleep,50
  58.  
  59.     dest=
  60.     text:=clipAnsi()
  61.     StringCaseSense,On
  62.     prevCharToEN=0
  63.     ;       АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ
  64.     RUtoEN=F<DULT:PBQRKVYJGHCNEA{WXIO}SM">Zf,dult;pbqrkvyjghcnea[wxio]sm'.z
  65.     RUtoSP1=хъжэбюХЪЖЭБЮ.,/";:?
  66.     RUtoSP2=[];',.{}:"<>/?|@#$^&
  67.     ;"       ABCDEFGHIJKLMNOPQRSTUVWXYZ
  68.     ENtoRU=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯфисвуапршолдьтщзйкыегмцчня
  69.  
  70.     loop,parse,text
  71.     {
  72.         destChar=%A_LoopField%
  73.  
  74.         ; check explicit (non punctuations) ranges
  75.         ifGreaterOrEqual,A_LoopField,А
  76.             prevCharToEN=1
  77.         else if A_LoopField between A and Z
  78.             prevCharToEN=0
  79.         else if A_LoopField between a and z
  80.             prevCharToEN=0
  81.  
  82.         ; to Russian
  83.         ifEqual,prevCharToEN,0
  84.         {   StringGetPos,i,RUtoEN,%A_LoopField%
  85.             ifEqual,ErrorLevel,0
  86.                 Transform,destChar,chr,% i + 0xC0
  87.             else
  88.             {   StringGetPos,i,RUtoSP2,%A_LoopField%
  89.                 ifEqual,ErrorLevel,0
  90.                     StringMid,destChar,RUtoSP1,% i+1, 1
  91.             }
  92.         }
  93.  
  94.         ; to English because nothing changed
  95.         ifEqual,destChar,%A_LoopField%
  96.         {
  97.             StringGetPos,i,ENtoRU,%A_LoopField%
  98.             ifEqual,ErrorLevel,0
  99.                 Transform,destChar,chr,% i + (i>=26 ? 71 : 65)
  100.             else ; check .,;':"[]{}
  101.             {   StringGetPos,i,RUtoSP1,%A_LoopField%
  102.                 ifEqual,ErrorLevel,0,StringMid,destChar,RUtoSP2,% i+1, 1
  103.             }
  104.             ifNotEqual,destChar,%A_LoopField%
  105.                 prevCharToEN=1
  106.         }
  107.         dest=%dest%%destChar%
  108.     }
  109.  
  110.     ; decide compatibility of unicode clipboard
  111.     WinGetClass,cls,A
  112.     if cls in TMsgEditor,wndclass_desked_gsk
  113.     {
  114.         ControlGetFocus,cls,A
  115.         ifInString,cls,TXTRichEdit
  116.             clipSetUnicode(dest)
  117.         else
  118.             Clipboard=%dest%
  119.     }
  120.     else
  121.         clipSetUnicode(dest)
  122.     sleep,50
  123.     send +{Insert}
  124.     sleep 50
  125.  
  126.     clipSetUnicode(clipSave)
  127.     LangSwitch()
  128. }
  129.  
  130. ; read unicode clipboard into ansi string
  131. clipAnsi()
  132. {
  133.     StringLen,L,Clipboard
  134.     L:=(L+1)*4
  135.     transform,ca_Clip,unicode
  136.     varSetCapacity(ca_WideText,L,0)
  137.     varSetCapacity(ca_AnsiText,L,0)
  138.     ; Convert UTF-8 to UTF-16.  CP_UTF8=65001
  139.     if dllCall("MultiByteToWideChar",uint,65001, uint,0, str,ca_Clip
  140.                   , uint,-1, str,ca_WideText, uint,L/2)
  141.         dllCall("WideCharToMultiByte",uint,0, uint,0, str,ca_WideText
  142.                   , uint,-1, str,ca_AnsiText, uint,L/2, uint,0, uint,0)
  143.         ; Convert UTF-16 to ANSI.  CP_ACP=0
  144.     return ca_AnsiText
  145. }
  146.  
  147. ;--------------------------------------------------------------
  148. ; copy ansi string to clipboard in unicode mode
  149. clipSetUnicode(cu_AnsiText)
  150. {
  151.     StringLen,L,cu_AnsiText
  152.     L:=(L+1)*4
  153.     varSetCapacity(cu_WideText,L,0)
  154.     varSetCapacity(cu_UTFtext,L,0)
  155.     ; ANSI to UTF-16.   CP_ACP=0
  156.     if dllCall("MultiByteToWideChar",uint,0, uint,0, str,cu_AnsiText
  157.                   , uint,-1, str,cu_WideText, uint,L/2)
  158.         dllCall("WideCharToMultiByte",uint,65001, uint,0, str,cu_WideText
  159.                   , uint,-1, str,cu_UTFtext, uint,L/2, uint,0, uint,0)
  160.         ; Convert UTF-16 to UTF-8.  CP_UTF8=65001
  161.     transform,clipboard,unicode,%cu_UTFtext%
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement