<?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="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16576&amp;type=atom" />
	<updated>2021-09-16T18:39:00Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16576</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149551#p149551" />
			<content type="html"><![CDATA[<p>Во-первых, чтобы присвоить переменной пустой массив, нужно использовать знак <strong>:=</strong>, а не <strong>=</strong>, иначе вы присваиваете не массив, а буквальный текст <strong>[]</strong>:<br /></p><div class="codebox"><pre><code>var = []
MsgBox, % var</code></pre></div><p>Во-вторых, массив тут не особо нужен, легче пользоваться простой строкой символов (именно символов, точнее, названий нажатых клавиш, а не их vk), просто добавляя последний в конец. Определить, что в конце строки нужная комбинация (13 цифр + Enter), можно через RegExMatch:<br /></p><div class="codebox"><pre><code>str := &quot;abcd0123456789012Enter&quot;
if RegExMatch(str, &quot;\d{13}Enter$&quot;)
   MsgBox, В конце строки 13 цифр и Enter</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-09-16T18:39:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149551#p149551</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149547#p149547" />
			<content type="html"><![CDATA[<p>Когда массив размером 14, то:<br />-Если в 14 ячейке 13, а в 1 по 13 ячейках от 48, до 57 (включительно): {F7} + перебор всего массива.<br />-Иначе очистить массив.<br />&quot;а в 1 по 13 ячейках от 48, до 57 (включительно)&quot; - или в ячейках не число 13</p>]]></content>
			<author>
				<name><![CDATA[jerry33]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41978</uri>
			</author>
			<updated>2021-09-16T07:25:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149547#p149547</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149508#p149508" />
			<content type="html"><![CDATA[<p>Опишите словами алгоритм, который пытались реализовать в скрипте.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-09-11T22:32:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149508#p149508</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149505#p149505" />
			<content type="html"><![CDATA[<p>Подскажите, где я ошибся?<br /></p><div class="codebox"><pre><code>global Array := []
Hook := InputHook(&quot;V&quot;)
Hook.KeyOpt(&quot;{All}&quot;, &quot;N&quot;)
Hook.OnKeyDown := Func(&quot;OnKeyDown&quot;)
Hook.OnKeyUp := Func(&quot;OnKeyUp&quot;)
Hook.Start()
Return

OnKeyDown(hook, vk, sc) {
   ;ToolTip % &quot;Нажата клавиша: &quot; . GetKeyName( Format(&quot;vk{:x}sc{:x}&quot;, vk, sc) )
   ;ToolTip % &quot;Нажата клавиша: &quot; . sc 
   if (vk ~= &quot;48|49|50|51|52|53|54|55|56|57|13&quot;){
      Array.Push(vk)
      while Array.MaxIndex() &gt; 15 { ;Array.Count()
         Array.RemoveAt(1, 1)
      }
      if (Array.MaxIndex() = 14) {
      for index, element in Array
      {
         if (index &lt; 14) &amp;&amp; (element &lt; 47 || element &gt; 58) {
            Array = []
         } else if (index = 14) &amp;&amp; (element != 13) {
            Array = []
         } else {
            ToolTip % Array[Array.MaxIndex()]
         }
      }
      }
   }
   Else {
       Array = []
   }
   ;ToolTip % Array[Array.MaxIndex()] Array.MaxIndex()
   SetTimer, RemoveToolTip, -5000
}

OnKeyUp(hook, vk, sc) {
   ;ToolTip % &quot;Отпущена клавиша: &quot; . GetKeyName( Format(&quot;vk{:x}sc{:x}&quot;, vk, sc) )
   ;SetTimer, RemoveToolTip, -2000
   ;ToolTip % Array[1]
   ;if (vk = 13){
   ;   Array := []
   ;}
}

RemoveToolTip:
ToolTip
return</code></pre></div><p>Array[1-13] - это индекс с 1 по 13.</p>]]></content>
			<author>
				<name><![CDATA[jerry33]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41978</uri>
			</author>
			<updated>2021-09-11T16:57:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149505#p149505</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149504#p149504" />
			<content type="html"><![CDATA[<p>А что значит Array[1-13] ?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-09-11T16:55:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149504#p149504</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149503#p149503" />
			<content type="html"><![CDATA[<p>Разобрался! Спасибо.<br />Исправленный вариант:<br /></p><div class="codebox"><pre><code>
global Array := []
Hook := InputHook(&quot;V&quot;)
Hook.KeyOpt(&quot;{All}&quot;, &quot;N&quot;)
Hook.OnKeyDown := Func(&quot;OnKeyDown&quot;)
Hook.OnKeyUp := Func(&quot;OnKeyUp&quot;)
Hook.Start()
Return

OnKeyDown(hook, vk, sc) {
   ;ToolTip % &quot;Нажата клавиша: &quot; . GetKeyName( Format(&quot;vk{:x}sc{:x}&quot;, vk, sc) )
   ;ToolTip % &quot;Нажата клавиша: &quot; . sc 
   if (vk ~= &quot;48|49|50|51|52|53|54|55|56|57|13&quot;){
      Array.Push(vk)
      while Array.MaxIndex() &gt; 14 { ;Array.Count()
         Array.RemoveAt(1, 1)
      }
      ;if ....  
   }
   Else {
       Array := []
   }
   ToolTip % Array[Array.MaxIndex()] Array.MaxIndex()
   SetTimer, RemoveToolTip, -5000
}

OnKeyUp(hook, vk, sc) {
   ;ToolTip % &quot;Отпущена клавиша: &quot; . GetKeyName( Format(&quot;vk{:x}sc{:x}&quot;, vk, sc) )
   ;SetTimer, RemoveToolTip, -2000
   ;ToolTip % Array[1]
   ;if (vk = 13){
   ;   Array := []
   ;}
}

RemoveToolTip:
ToolTip
return
</code></pre></div><p>Такой вопрос: Как проверить каждый элемент массива на нужное мне условие? (На данный момент только IF знаю, но наверное можно как-то компактнее..)<br />Условие: Array[14] = 13 всегда, а Array[1-13] = 48 - 57<br />+++<br />Даже по другому: Array[14] = 13 всегда, Array[1-13] не ровно 13</p>]]></content>
			<author>
				<name><![CDATA[jerry33]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41978</uri>
			</author>
			<updated>2021-09-11T15:48:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149503#p149503</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149501#p149501" />
			<content type="html"><![CDATA[<p>А зачем вы vk в квадратные скобки взяли?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-09-11T13:37:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149501#p149501</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149500#p149500" />
			<content type="html"><![CDATA[<p>Можно подсказку: где объявлять переменную, что-бы функция имела к ней доступ?<br />Не понимаю, почему ==ToolTip % Array[1]== в первом случае срабатывает, как и ожидается, а во втором (внутри функции) - ни как...</p><div class="codebox"><pre><code>
Array := []
Array.Push(50)
ToolTip % Array[1]
SetTimer, RemoveToolTip, -5000
Hook := InputHook(&quot;V&quot;)
Hook.KeyOpt(&quot;{All}&quot;, &quot;N&quot;)
Hook.OnKeyDown := Func(&quot;OnKeyDown&quot;)
Hook.OnKeyUp := Func(&quot;OnKeyUp&quot;)
Hook.Start()
Return

OnKeyDown(hook, vk, sc) {
   ;ToolTip % &quot;Нажата клавиша: &quot; . GetKeyName( Format(&quot;vk{:x}sc{:x}&quot;, vk, sc) )
   Array.Push([vk])
   ToolTip % Array[1]
   SetTimer, RemoveToolTip, -5000
}

OnKeyUp(hook, vk, sc) {
   ;ToolTip % &quot;Отпущена клавиша: &quot; . GetKeyName( Format(&quot;vk{:x}sc{:x}&quot;, vk, sc) )
   ;SetTimer, RemoveToolTip, -2000
}

RemoveToolTip:
ToolTip
return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[jerry33]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41978</uri>
			</author>
			<updated>2021-09-11T13:08:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149500#p149500</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149492#p149492" />
			<content type="html"><![CDATA[<p>Следить за нажатиями клавиш удобно через <a href="https://www.autohotkey.com/docs/commands/InputHook.htm">InputHook()</a>. Сохранять нажатые клавиши можно в массив в момент нажатия, и удалять из массива в момент отжатия.<br /><a href="https://forum.script-coding.com/viewtopic.php?pid=149411#p149411">Вот пример</a> использования InputHook().</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-09-08T18:24:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149492#p149492</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149490#p149490" />
			<content type="html"><![CDATA[<p>Нет, всегда разные, одинаково только их кол-во и Enter в конце.<br />(Но интересен вариант и с одной комбинацией. Что-то типа скрытого кода на компьютере. Это лучше в следующих сообщениях обсудить ;-) )<br />Или вопрос по другому можно поставить:<br />Как сделать, что бы AHK помнил последние несколько нажатий?<br />Пример: было 4 нажатия - 1,3,3,2 =&gt; AHK их запомнил 1332<br />Нажимаешь 5 =&gt; теперь AHK помнит 3325<br />Нажимаешь 7 =&gt; теперь AHK помнит 3257<br />И так далее..</p><p>Как я это представляю на словах: AHK следит за нажатиями клавиш, если это цифра - записывает в переменную (буфер объемом в Х символов).<br />Нажимается Enter - если в буфере X цифр, то F7+вывод буфера+Enter<br />Если нажимается всё остальное - буфер очищается.</p>]]></content>
			<author>
				<name><![CDATA[jerry33]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41978</uri>
			</author>
			<updated>2021-09-08T10:38:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149490#p149490</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149489#p149489" />
			<content type="html"><![CDATA[<p>Цифры всегда одни и те же?</p>]]></content>
			<author>
				<name><![CDATA[Foma]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=31521</uri>
			</author>
			<updated>2021-09-08T10:26:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149489#p149489</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Срабатывание при нажатии определенной комбинации с запоминанием]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149488#p149488" />
			<content type="html"><![CDATA[<p>Всем привет. Есть такие условия:<br />Идёт набор 13 цифр (меньше секунды) и нажимается Enter.</p><p>Что должно получиться:<br />Если идёт последовательное нажатие 13 цифр + Enter - то нажимается F7 + 13 цифр + Enter.</p><p>Подскажите, как это реализовать?<br />Отслеживать, когда нажимается цифра и если да, то следующая цифра, если да, то .. и так далее?<br />Или есть более компактный способ?</p>]]></content>
			<author>
				<name><![CDATA[jerry33]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41978</uri>
			</author>
			<updated>2021-09-08T09:10:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149488#p149488</id>
		</entry>
</feed>
