<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Смена раскладки написанного текста]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7186&amp;type=atom" />
	<updated>2016-04-06T00:29:45Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7186</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Смена раскладки написанного текста]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=102343#p102343" />
			<content type="html"><![CDATA[<p>Новый вариант. Исправлен отказ переводить в другую раскладку в некоторых случаях, увеличена скорость. Добавлена возможность конвертации после введённого пробела или перевода строки.</p><p>Скрипт меняет раскладку <em>выделенного текста</em> или <em>последнего слова слева от каретки</em> по Ctrl + Page Down, как программа Punto Switcher, по Shift + Page Down переключает регистр (когда текст введён с ошибочно включенным CapsLock).<br /></p><div class="codebox"><pre><code>^PGDN::SwitchKeysLocale()   ; Ctrl + Page Down
+PGDN::SwitchRegistr()      ; Shift + Page Down

SwitchKeysLocale()
{
   SelText := GetWord(TempClipboard) 
   Clipboard := ConvertText(SelText, Layout)
   SendInput, ^{vk56}   ; Ctrl + V
   Sleep, 50
   SwitchLocale(Layout)
   Sleep, 50
   Clipboard := TempClipboard
}

SwitchRegistr()
{
   SelText := GetWord(TempClipboard)
   Clipboard := ConvertRegistr(SelText) 
   SendInput, ^{vk56}   ; Ctrl + V 
   Sleep, 200 
   Clipboard := TempClipboard
}

GetWord(ByRef TempClipboard)
{
   SetBatchLines, -1
   SetKeyDelay, 0
   
   TempClipboard := ClipboardAll
   Clipboard =
   SendInput, ^{vk43}
   Sleep, 100
   if (Clipboard != &quot;&quot;)
      Return Clipboard
   
   While A_Index &lt; 10
   {
      SendInput, ^+{Left}^{vk43}
      ClipWait, 1
      if ErrorLevel
         Return

      if RegExMatch(Clipboard, &quot;P)([ \t])&quot;, Found) &amp;&amp; A_Index != 1
      {
         SendInput, ^+{Right}
         Return SubStr(Clipboard, FoundPos1 + 1)
      }

      PrevClipboard := Clipboard
      Clipboard =
      SendInput, +{Left}^{vk43}
      ClipWait, 1
      if ErrorLevel
         Return

      if (StrLen(Clipboard) = StrLen(PrevClipboard))
      {
         Clipboard =
         SendInput, +{Left}^{vk43}
         ClipWait, 1
         if ErrorLevel
            Return

         if (StrLen(Clipboard) = StrLen(PrevClipboard))
            Return Clipboard
         Else
         {
            SendInput, +{Right 2}
            Return PrevClipboard
         }
      }

      SendInput, +{Right}

      s := SubStr(Clipboard, 1, 1)
      if s in %A_Space%,%A_Tab%,`n,`r
      {
         Clipboard =
         SendInput, +{Left}^{vk43}
         ClipWait, 1
         if ErrorLevel
            Return

         Return Clipboard
      }
      Clipboard =
   }
}

ConvertText(Text, ByRef OppositeLayout)
{  
   Static Cyr := &quot;ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ/ёйцукенгшщзхъфывапролджэячсмитьбю,.&quot;&quot;№;?:&quot;
        , Lat := &quot;~QWERTYUIOP{}ASDFGHJKL:&quot;&quot;ZXCVBNM&lt;&gt;|``qwertyuiop[]asdfghjkl;&#039;zxcvbnm,.?/@#$&amp;^&quot;

   RegExReplace(Text, &quot;i)[A-Z@#\$\^&amp;\[\]&#039;`\{}]&quot;, &quot;&quot;, LatCount)
   RegExReplace(Text, &quot;i)[А-ЯЁ№]&quot;, &quot;&quot;, CyrCount)
   
   if (LatCount != CyrCount)  {
      CurrentLayout := LatCount &gt; CyrCount ? &quot;Lat&quot; : &quot;Cyr&quot;
      OppositeLayout := LatCount &gt; CyrCount ? &quot;Cyr&quot; : &quot;Lat&quot;
   }
   else  {
      threadId := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, WinExist(&quot;A&quot;), UInt, 0, Ptr)
      landId := DllCall(&quot;GetKeyboardLayout&quot;, Ptr, threadId, Ptr) &amp; 0xFFFF
      if (landId = 0x409)
         CurrentLayout := &quot;Lat&quot;, OppositeLayout := &quot;Cyr&quot;
      else
         CurrentLayout := &quot;Cyr&quot;, OppositeLayout := &quot;Lat&quot;
   }
   Loop, parse, Text
      NewText .= (found := InStr(%CurrentLayout%, A_LoopField, 1)) 
         ? SubStr(%OppositeLayout%, found, 1) : A_LoopField
   Return NewText
}

SwitchLocale(Layout)
{
   ControlGetFocus, CtrlFocus, A
   PostMessage, WM_INPUTLANGCHANGEREQUEST := 0x50,, Layout = &quot;Lat&quot; ? 0x4090409 : 0x4190419, %CtrlFocus%, A
}

ConvertRegistr(Text)
{
   static Chars := &quot;ёйцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnm&quot;
                 . &quot;ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮQWERTYUIOPASDFGHJKLZXCVBNM&quot; 

   Loop, parse, Text
      NewText .= (found := InStr(Chars, A_LoopField, 1)) 
         ? SubStr(Chars, found - 59, 1) : A_LoopField
   Return NewText
}</code></pre></div><p>Функция <em>ConvertRegistr()</em>, доработка <em>ConvertText()</em> — <strong>serzh82saratov</strong><br />Функция <em>SwitchLocale()</em> — <strong>YMP</strong><br /><a href="http://forum.script-coding.com/viewtopic.php?id=6393">Тема для обсуждения</a></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-04-06T00:29:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=102343#p102343</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Смена раскладки написанного текста]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=82490#p82490" />
			<content type="html"><![CDATA[<p>Новая версия. Добавлено переключение регистра выделенного текста или последнего слова слева от каретки (введённого с ошибочно включенным CapsLock).<br /></p><div class="codebox"><pre><code>^PGDN::SwitchKeysLocale()   ; Ctrl + Page Down
+PGDN::SwitchRegistr()      ; Shift + Page Down

SwitchKeysLocale()
{
   SelText := GetWord(TempClipboard) 
   Clipboard := ConvertText(SelText, Layout)
   SendInput, ^{vk56} 
   Sleep, 50
   SwitchLocale(Layout)
   Sleep, 50
   Clipboard := TempClipboard
}

SwitchRegistr()
{
   SelText := GetWord(TempClipboard)
   Clipboard := ConvertRegistr(SelText) 
   SendInput, ^{vk56}   ; Ctrl + V 
   Sleep, 200 
   Clipboard := TempClipboard
}

GetWord(ByRef TempClipboard)
{
   Critical
   SetBatchLines, -1
   SetKeyDelay, 0
   
   TempClipboard := ClipboardAll
   Clipboard =
   SendInput, ^{vk43}
   ClipWait, 0
   if !ErrorLevel
      Return Clipboard
   
   While A_Index &lt; 10
   {
      Clipboard =
      SendInput, ^+{Left}^{vk43}
      ClipWait, 1
      if ErrorLevel
         Return

      if RegExMatch(Clipboard, &quot;P)([ \t])&quot;, Found)
      {
         SendInput, ^+{Right}
         Return SubStr(Clipboard, FoundPos1 + 1)
      }

      PrevClipboard := Clipboard
      Clipboard =
      SendInput, +{Left}^{vk43}
      ClipWait, 1
      if ErrorLevel
         Return

      if (StrLen(Clipboard) = StrLen(PrevClipboard))
      {
         Clipboard =
         SendInput, +{Left}^{vk43}
         ClipWait, 1
         if ErrorLevel
            Return

         if (StrLen(Clipboard) = StrLen(PrevClipboard))
            Return Clipboard
         Else
         {
            SendInput, +{Right 2}
            Return PrevClipboard
         }
      }

      SendInput, +{Right}

      s := SubStr(Clipboard, 1, 1)
      if s in %A_Space%,%A_Tab%,`n,`r
      {
         Clipboard =
         SendInput, +{Left}^{vk43}
         ClipWait, 1
         if ErrorLevel
            Return

         Return Clipboard
      }
   }
}

ConvertText(Text, ByRef OppositeLayout)
{  
   static Cyr := &quot;ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮёйцукенгшщзхъфывапролджэячсмитьбю,.&quot;&quot;№;?&quot;
        , Lat := &quot;~QWERTYUIOP{}ASDFGHJKL:&quot;&quot;ZXCVBNM&lt;&gt;``qwertyuiop[]asdfghjkl;&#039;zxcvbnm,.?/@#$&amp;&quot;  

   RegExReplace(Text, &quot;i)[A-Z]&quot;, &quot;&quot;, LatCount)
   RegExReplace(Text, &quot;i)[А-ЯЁ]&quot;, &quot;&quot;, CyrCount)
   CurrentLayout := LatCount &gt; CyrCount ? &quot;Lat&quot; : &quot;Cyr&quot;
   OppositeLayout := LatCount &gt; CyrCount ? &quot;Cyr&quot; : &quot;Lat&quot;

   Loop, parse, Text
      NewText .= (found := InStr(%CurrentLayout%, A_LoopField, 1)) 
         ? SubStr(%OppositeLayout%, found, 1) : A_LoopField
   Return NewText
}

SwitchLocale(Layout)
{
   ControlGetFocus, CtrlFocus, A
   PostMessage, WM_INPUTLANGCHANGEREQUEST := 0x50,, Layout = &quot;Lat&quot; ? 0x4090409 : 0x4190419, %CtrlFocus%, A
}

ConvertRegistr(Text)
{
   static Chars := &quot;ёйцукенгшщзхъфывапролджэячсмитьбюqwertyuiopasdfghjklzxcvbnm&quot;
                 . &quot;ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮQWERTYUIOPASDFGHJKLZXCVBNM&quot; 

   Loop, parse, Text
      NewText .= (found := InStr(Chars, A_LoopField, 1)) 
         ? SubStr(Chars, found - 59, 1) : A_LoopField
   Return NewText
}</code></pre></div><p>Функция <em>ConvertRegistr()</em>, доработка <em>ConvertText()</em> — <strong>serzh82saratov</strong><br />Функция <em>SwitchLocale()</em> — <strong>YMP</strong><br /><a href="http://forum.script-coding.com/viewtopic.php?id=6393">Тема для обсуждения</a></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2014-04-30T15:01:57Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=82490#p82490</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Смена раскладки написанного текста]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=59993#p59993" />
			<content type="html"><![CDATA[<p>Работает под <a href="http://ahkscript.org/">AHK_L</a>.<br />Скрипт меняет раскладку выделенного текста или последнего слова слева от каретки по Shift + Break, как программа Punto Switcher.<br /></p><div class="codebox"><pre><code>+Break::SwitchKeysLocale()

SwitchKeysLocale()
{
   Critical
   SetBatchLines, -1
   SetKeyDelay, 0

   TempClipboard := ClipboardAll
   Clipboard =
   SendInput, ^{vk43}   ; Ctrl + C
   ClipWait, 0
; если буфер обмена пуст (ничего не выделено), определяем и выделяем
; с помощью ф-ции GetWord() последнее слово слева от курсора
   SelText := ErrorLevel ? GetWord() : Clipboard
   pResult := ConvertText(SelText)   ; получаем конвертированный текст и раскладку последней найденной буквы

   Clipboard := StrGet(pResult + A_PtrSize)
   SendInput, ^{vk56}   ; Ctrl + V
; переключаем раскладку клавиатуры в зависимости от раскладки последней найденной буквы
   Sleep, 200
   SwitchLocale(NumGet(pResult+0, &quot;UInt&quot;))
   Sleep, 200
   Clipboard := TempClipboard
}

GetWord()
{
   While A_Index &lt; 10
   {
      Clipboard =
      SendInput, ^+{Left}^{vk43}
      ClipWait, 1
      if ErrorLevel
         Return

      if RegExMatch(Clipboard, &quot;P).*([ \t])&quot;, Found)
      {
         SendInput, ^+{Right}
         Return SubStr(Clipboard, FoundPos1 + 1)
      }

      PrevClipboard := Clipboard
      Clipboard =
      SendInput, +{Left}^{vk43}
      ClipWait, 1
      if ErrorLevel
         Return

      if (StrLen(Clipboard) = StrLen(PrevClipboard))
      {
         Clipboard =
         SendInput, +{Left}^{vk43}
         ClipWait, 1
         if ErrorLevel
            Return

         if (StrLen(Clipboard) = StrLen(PrevClipboard))
            Return Clipboard
         Else
         {
            SendInput, +{Right 2}
            Return PrevClipboard
         }
      }

      SendInput, +{Right}

      s := SubStr(Clipboard, 1, 1)
      if s in %A_Space%,%A_Tab%,`n,`r
      {
         Clipboard =
         SendInput, +{Left}^{vk43}
         ClipWait, 1
         if ErrorLevel
            Return

         Return Clipboard
      }
   }
}

ConvertText(Text)
{
   static Result

   Cyr := &quot;ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮёйцукенгшщзхъфывапролджэячсмитьбю,?&quot;&quot;№&quot;
   Lat := &quot;~QWERTYUIOP{}ASDFGHJKL:&quot;&quot;ZXCVBNM&lt;&gt;``qwertyuiop[]asdfghjkl;&#039;zxcvbnm,.?&amp;@#&quot;

   Loop, parse, Text
   {
      found =
      if found := InStr(Lat, A_LoopField, 1)
         NewText .= SubStr(Cyr, found, 1), lastfound := 2

      if !found
         if found := InStr(Cyr, A_LoopField, 1)
            NewText .= SubStr(Lat, found, 1), lastfound := 1

      if !found
         NewText .= A_LoopField
   }
   VarSetCapacity(Result, A_PtrSize + StrPut(NewText)*(A_IsUnicode ? 2 : 1))
   NumPut(lastfound, &amp;Result), StrPut(NewText, &amp;Result + A_PtrSize)
   Return &amp;Result
}

SwitchLocale(lastfound)
{
   SetFormat, IntegerFast, H
   VarSetCapacity(List, A_PtrSize*2)
   DllCall(&quot;GetKeyboardLayoutList&quot;, Int, 2, Ptr, &amp;List)
   Locale1 := NumGet(List)
   b := SubStr(Locale2 := NumGet(List, A_PtrSize), -3) = 0409
   En := b ? Locale2 : Locale1
   Ru := b ? Locale1 : Locale2
   SendMessage, WM_INPUTLANGCHANGEREQUEST := 0x50,, lastfound = 1 ? En : Ru,, A
}</code></pre></div><p><a href="http://forum.script-coding.com/viewtopic.php?id=6393">Тема для обсуждения</a>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2012-05-05T18:24:56Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=59993#p59993</id>
		</entry>
</feed>
