<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=11599&amp;type=atom" />
	<updated>2017-09-18T12:03:11Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=11599</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=119405#p119405" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong>, функция <em>DragSearch </em> находит координаты на основе найденных изображений из предложенных. В моем случае, при удачном срабатывании сценария, изображение из конечной координаты для перетаскивания всегда меняется на одно из заданных, но так как скрипт не всегда срабатывает с первого раза, хотелось бы добавить сравнение данного изображения после команды <em>MouseClickDrag</em>, и в случае, если изображение осталось неизменным, повторить <em>MouseClickDrag</em>.</p><p>Например, в моем случае, конечной координатой может быть изображение с индексом от 1 до 4:<br /></p><div class="codebox"><pre><code>
If DragSearch(100, 100, 1300, 725, [[&quot;image&quot;, 1, 2, &quot;png&quot;], [&quot;2nd-image&quot;, 1, 4,&quot;png&quot;]], M) {
	MouseClickDrag, Left, M.X1, M.Y1, M.X2, M.Y2
}
Return
</code></pre></div><p>Далее, к примеру, функция обнаружила изображение 2nd-image3, после чего записала его положение в качестве конечной координаты для перетаскивания. Потом, после перетаскивания, это изображение сменилось на любое другое из заданных, например, 2nd-image1 или 2nd-image4 - это значит, что скрипт закончил работу корректно. Но если изображение осталось прежним, т.е. 2nd-image3 - необходимо повторить <em>MouseClickDrag</em>.</p><p>Как добавить в сценарий такое сравнение?</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-09-18T12:03:11Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=119405#p119405</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111447#p111447" />
			<content type="html"><![CDATA[<p><strong>KusochekDobra</strong>, Спасибо! Попытаюсь проанализировать описание приложив его к сценарию.</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-01-23T13:38:10Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111447#p111447</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111446#p111446" />
			<content type="html"><![CDATA[<p>Циклы &quot;While (условие)&quot; выполняются, пока &quot;условие&quot; возвращает &quot;истина&quot;. В том примере &quot;истиной&quot; является само условие, поэтому цикл бесконечный. Это просто пример. Вы же приобщаетесь ко всеобщей мудрости, верно? Полезно, когда примеры разнообразны.<br />В примере <strong>serzh82saratov</strong> нет регулярных выражений. Очень содержательный в плане разнообразия пример.<br />DragSearch() - принимает после координат области поиска, массив, с массивами данных о двух типах фрагментов, которые предполагается найти. В них параметры по счёту:<br /> 1 - имя/путь файла без расширения(напр.:&quot;Изображение&quot; или &quot;C:\MyFolder\Изображение&quot;).<br /> 2 - первый индекс изображения(напр.:&quot;Изображение0&quot;, где 0 - его индекс).<br /> 3 - последний индекс изображения(напр.:&quot;Изображение3&quot;, где 3 - его индекс).<br /> 4 - расширение файла изображения.<br />После чего, оба массива перебираются по очереди в пределах разницы индексов между третьим и вторым параметром. Если изображение было найдено, его координаты присваиваются полям объекта &quot;arr&quot;, который связан по ссылке с параметром &quot;M&quot; в вызове функции DragSearch() и происходит переход ко второму массиву, с данными о другом изображении. Если перебор цикла завершился а изображение не было найдено, DragSearch() завершает работу возвращая вызывающему коду &quot;ложь&quot;. В этом случае &quot;MouseClickDrag&quot; произведено не будет, иначе, значения присвоенные полям объекта &quot;M&quot; извлекаются оператором &quot;.&quot;(точка) прямо в процессе &quot;MouseClickDrag&quot; и происходит ожидаемый эффект.</p><p>Как всегда, &quot;E=MC2&quot;! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2017-01-23T12:57:23Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111446#p111446</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111428#p111428" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong>, извиняюсь, все-таки я неверно внес данные о файлах. Все работает. Спасибо! Конечно, мне совсем не ясна структура функции в виду ее оформления посредством регулярных выражений. В этом смысле вариант от <strong>KusochekDobra</strong> проще для понимания. Только интересно, почему цикличный поиск в <a href="http://forum.script-coding.com/viewtopic.php?pid=111411#p111411">его варианте</a> оформлен не с помощью <em>loop</em>, а с помощью <em>while (true)</em>. Конечно, я бы его исключил, т.к. необходим поиск по горячей клавише, но все-таки интересно, в чем отличие и как это работает.</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-01-22T22:59:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111428#p111428</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111427#p111427" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>[[&quot;PicOne&quot;, 1, 2, &quot;png&quot;], [&quot;PicTwo&quot;, 1, 3, &quot;png&quot;]]</code></pre></div><p>Из этого:<br /></p><div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>[&quot;&quot;, 0, 3, &quot;png&quot;] - ищем сначала от 0.png до 3.png.<br />[&quot;a&quot;, 1, 4,&quot;png&quot;] - после от a1.png до а4.png. Вместо первого ключа &quot;a&quot; (префикса) может быть и путь до числа.</p></blockquote></div><p>Вроде такой же вывод получается.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-01-22T22:17:58Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111427#p111427</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111426#p111426" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong>, изображений в моем случае всего пять: PicOne1.png, PicOne2.png, PicTwo1.png, PicTwo2.png, PicTwo3.png.</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-01-22T22:14:23Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111426#p111426</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111425#p111425" />
			<content type="html"><![CDATA[<p>Ну то есть 2 картинки PicOne1.png и PicTwo1.png, а индексы зачем, если их всего 2?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-01-22T21:42:07Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111425#p111425</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111424#p111424" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong>, изображения кладу рядом со скриптом, поэтому, полный путь выглядит именно так.</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-01-22T21:39:58Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111424#p111424</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111423#p111423" />
			<content type="html"><![CDATA[<p>Ну а искать то какие надо пути?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-01-22T21:33:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111423#p111423</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111422#p111422" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>If DragSearch(100, 100, 1300, 725, [[&quot;&quot;, 0, 3, &quot;PicOne.png&quot;], [&quot;a&quot;, 1, 4,&quot;PicTwo.png&quot;]], M) 
</code></pre></div><p> Насчет необходимости дописывания индексов в Вашем варианте не в курсе, поэтому, пробовал указывать и оригинальные названия: PicOne1.png, PicTwo1.png</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-01-22T21:30:53Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111422#p111422</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111421#p111421" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>becauseim пишет:</cite><blockquote><p>Внес в кавычки вместо &quot;png&quot; полные пути к изображениям</p></blockquote></div><p>Это как?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-01-22T21:10:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111421#p111421</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111420#p111420" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong>, спасибо! Но кажется, я не понял, как использовать такой вариант. Внес в кавычки вместо &quot;png&quot; полные пути к изображениям - не сработало. Пользуюсь простым вариантом от <strong>Malcev</strong>.</p>]]></content>
			<author>
				<name><![CDATA[becauseim]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=33149</uri>
			</author>
			<updated>2017-01-22T21:08:49Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111420#p111420</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111418#p111418" />
			<content type="html"><![CDATA[<p>Лучше сразу так:<br /></p><div class="codebox"><pre><code>#SingleInstance Force
#NoEnv
ListLines Off
SetBatchLines -1
CoordMode, Pixel
CoordMode, Mouse

1:: 
	If DragSearch(100, 100, 1300, 725, [[&quot;&quot;, 0, 3, &quot;png&quot;], [&quot;a&quot;, 1, 4,&quot;png&quot;]], M) 
		MouseClickDrag, Left, M.X1, M.Y1, M.X2, M.Y2, 10
	Return
 

DragSearch(x1, y1, x2, y2, r, byref arr)  { 
	For i, v in r, arr := {}
		Loop % (c := v[3] - v[2] + 1) {
			ImageSearch, mX, mY, x1, y1, x2, y2, % v[1] (v[2] - 1 + A_Index) &quot;.&quot; v[4]
			If !ErrorLevel &amp;&amp; (1, arr[&quot;X&quot; i] := mX, arr[&quot;Y&quot; i] := mY) 
				Break
			If (A_Index = c)
				Return 0, arr := &quot;&quot;
		} Return 1
}

Esc::
	ExitApp</code></pre></div><p>А то вдруг понадобится не 2 группы картинок, а 10.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-01-22T20:25:05Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111418#p111418</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111417#p111417" />
			<content type="html"><![CDATA[<p>[&quot;&quot;, 0, 3, &quot;png&quot;] - ищем сначала от 0.png до 3.png.<br />[&quot;a&quot;, 1, 4,&quot;png&quot;] - после от a1.png до а4.png. Вместо первого ключа &quot;a&quot; (префикса) может быть и путь до числа.</p><div class="codebox"><pre><code>
#SingleInstance Force
#NoEnv
CoordMode, Pixel
CoordMode, Mouse 

1:: 
	If DragSearch(100, 100, 1300, 725, [&quot;&quot;, 0, 3, &quot;png&quot;], [&quot;a&quot;, 1, 4,&quot;png&quot;], M) 
		MouseClickDrag, Left, M.X1, M.Y1, M.X2, M.Y2, 0
	Return

DragSearch(x1, y1, x2, y2, r1, r2, byref arr)  {
	Loop % 2 . (arr := {})
		Loop % (i := A_Index) * 0 + (c := r%i%[3] - r%i%[2] + 1)
		{
			ImageSearch, mX, mY, x1, y1, x2, y2, % r%i%[1] (r%i%[2] - 1 + A_Index) &quot;.&quot; r%i%[4]
			If !ErrorLevel &amp;&amp; (1, arr[&quot;X&quot; i] := mX, arr[&quot;Y&quot; i] := mY) 
				Break
			If (A_Index = c)
				Return 0, arr := &quot;&quot;
		}
	Return 1
}

Esc::
	ExitApp
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-01-22T20:16:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111417#p111417</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: ImageSearch. Найти все элементы, соответствующие критериям]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111415#p111415" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Интересно было бы взглянуть на функцию.</p></blockquote></div><p>Так сделайте. По аналогии:<br /><a href="http://www.script-coding.com/AutoHotkey/Functions.html">http://www.script-coding.com/AutoHotkey/Functions.html</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2017-01-22T16:55:38Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111415#p111415</id>
		</entry>
</feed>
