<?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=5329&amp;type=atom" />
	<updated>2011-02-13T09:15:14Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5329</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45101#p45101" />
			<content type="html"><![CDATA[<p>Примеры прекрасно в ней работают под W7 64.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2011-02-13T09:15:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45101#p45101</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45096#p45096" />
			<content type="html"><![CDATA[<p>Нет. Я имею ввиду basic версию.</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2011-02-13T08:42:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45096#p45096</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45095#p45095" />
			<content type="html"><![CDATA[<p>Я как раз сейчас на ней, они прекрасно работают. Или имеете в виду АНК_64?</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2011-02-13T08:37:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45095#p45095</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45091#p45091" />
			<content type="html"><![CDATA[<p>Как заставить работать код из поста #22 или #23 на Windows7 64 бит?<br />Достаточно ли будет просто поменять строку<br /></p><div class="codebox"><pre><code> NumPut(WI, VarSetCapacity(WI, 60))</code></pre></div><p>на<br /></p><div class="codebox"><pre><code> NumPut(WI, VarSetCapacity(WI, 120))</code></pre></div><p>или что-то еще надо исправлять?</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2011-02-13T07:52:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45091#p45091</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43357#p43357" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Вот немного упрощённый код для клиентской области.</p></blockquote></div><p>В таком варианте функция<br /></p><div class="codebox"><pre><code>DllCall(&quot;ClipCursor&quot;, UInt, &amp;WI + 20)</code></pre></div><p>бесполезно выполняется много раз подряд. На самом деле всё ещё проще, если не предполагается менять положение и размеры окна во время клипирования курсора:<br /></p><div class="codebox"><pre><code>   OnExit, Exit

   Run, notepad.exe,,, PID
   WinWait, ahk_pid %PID%
   WinGet, hTargetWin, ID, ahk_pid %PID%

   NumPut(WI, VarSetCapacity(WI, 60))
   SetTimer, WinExist
   Gosub, WGP
   Return

WinExist:
   if !WinExist(&quot;ahk_id &quot; hTargetWin)
      ExitApp
      
   WinGet, AID, ID, A
   if (AID != hTargetWin)
   {
      if !NotActiveTarget
         DllCall(&quot;ClipCursor&quot;, UInt, 0), NotActiveTarget := 1
      Return
   }
   Else if (!switch &amp;&amp; NotActiveTarget)
      Gosub, WGP
   Return

WGP:
   NotActiveTarget =
   DllCall(&quot;GetWindowInfo&quot;, UInt, hTargetWin, UInt, &amp;WI)
   DllCall(&quot;ClipCursor&quot;, UInt, &amp;WI + 20)
   Return

F11::
   if (switch := !switch)
      DllCall(&quot;ClipCursor&quot;, UInt, 0)
   Else
      Gosub, WGP
   Return

Esc:: ExitApp

Exit:
   DllCall(&quot;ClipCursor&quot;, UInt, 0)
   ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-01-06T12:53:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43357#p43357</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43353#p43353" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>InFlames пишет:</cite><blockquote><p>И подскажите от куда вы берете числа 48 и 52 для W и H границ?<br /><a href="http://msdn.microsoft.com/en-us/library/ms632610%28v=VS.85%29.aspx">Тут</a> описана структура Windowinfo, но там 10 параметров.<br />На каждый параметр отводится свое кол-во байт? Как это узнать?</p></blockquote></div><p>Думаю, из интернета не проблема это узнать. DWORD = (U)INT = (U)LONG = 4 байта. WORD = ATOM = 2 байта. RECT — структура из 4 LONG, т.е. 16 байт.</p><p>Хэндлы и указатели имеют разную величину: для 32-битных программ они по 4 байта, для 64-битных по 8. Т.е. тут имеет значение разрядность версии AutoHotkey, которую Вы используете, а не операционной системы.</p><p>rcClient по идее как раз и содержит координаты клиентской области окна, так что заморачиваться с толщиной границ вроде незачем.</p><p>Вот немного упрощённый код для клиентской области.<br /></p><div class="codebox"><pre><code>   OnExit, Exit
   
   Run, notepad.exe,,, PID
   WinWait, ahk_pid %PID%
   WinGet, hTargetWin, ID, ahk_pid %PID%
   
   NumPut(WI, VarSetCapacity(WI, 60))
   
   SetTimer, WGP, 10
   SetTimer, WinExist
   Return
   
WinExist:
   if !WinExist(&quot;ahk_id &quot; hTargetWin)
      ExitApp
   Return

WGP:
   IfWinNotActive, ahk_id %hTargetWin%
   {
      If !NotActiveTarget
        DllCall(&quot;ClipCursor&quot;, UInt, 0), NotActiveTarget := 1
      Return
   }
   NotActiveTarget =
   DllCall(&quot;GetWindowInfo&quot;, UInt, hTargetWin, UInt, &amp;WI)
   DllCall(&quot;ClipCursor&quot;, UInt, &amp;WI + 20)   
   Return
   
F11::
   if (switch := !switch)
   {
      SetTimer, WGP, Off
      DllCall(&quot;ClipCursor&quot;, UInt, 0)
   }
   Else
      SetTimer, WGP, On
   Return
   
Esc:: ExitApp

Exit:
   DllCall(&quot;ClipCursor&quot;, UInt, 0)
   ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2011-01-06T10:21:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43353#p43353</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43352#p43352" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, да, нужно всё, кроме заголовка и окантовки. Строки меню в игре нет.<br />Впринципе вариант из поста #17 устраивает.<br />Вопрос в одном у всех ли окантовка окон с трех сторон по 8, сверху 30?<br />Или лучше определять это через WINDOWINFO ?<br />И подскажите от куда вы берете числа 48 и 52 для W и H границ?<br /><a href="http://msdn.microsoft.com/en-us/library/ms632610%28v=VS.85%29.aspx">Тут</a> описана структура Windowinfo, но там 10 параметров.<br />На каждый параметр отводится свое кол-во байт? Как это узнать?</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2011-01-06T09:31:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43352#p43352</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43349#p43349" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />По моим подсчётам размер WINDOWINFO — 60 байт.<br />F11 отключает захват, но повторное нажатие — не включает, если положение окна за это время не изменилось.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2011-01-06T03:32:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43349#p43349</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43346#p43346" />
			<content type="html"><![CDATA[<p>Это всё вряд ли.<br />Проще по горячей клавише останавливать таймер, высвобождать курсор, затем снова запускать. Тогда для слежения за существованием окна нужен отдельный таймер. Клавиша <strong>F11</strong>. Кстати, из предыдущего варианта две важных строчки выпали:<br /></p><div class="codebox"><pre><code>    if (X = XPrev &amp;&amp; Y = YPrev &amp;&amp; W = WPrev &amp;&amp; H = HPrev)
        Return</code></pre></div><div class="codebox"><pre><code>   OnExit, Exit
   
   Run, notepad.exe,,, PID
   WinWait, ahk_pid %PID%
   WinGet, hTargetWin, ID, ahk_pid %PID%
   
   NumPut(WI, VarSetCapacity(WI, 56))
   DllCall(&quot;GetWindowInfo&quot;, UInt, hTargetWin, UInt, &amp;WI)
   WBorder := NumGet(WI, 48)
   HBorder := NumGet(WI, 52)
   Border := WBorder &gt; HBorder ? WBorder : HBorder
   
   VarSetCapacity(RECT, 16)
   SetTimer, WGP
   SetTimer, WinExist
   Return
   
WinExist:
   if !WinExist(&quot;ahk_id &quot; hTargetWin)
      ExitApp
   Return

WGP:
   WinGet, AID, ID, A
   if (AID != hTargetWin)
   {
      if !NotActiveTarget
         DllCall(&quot;ClipCursor&quot;, UInt, 0), NotActiveTarget := 1, XPrev := &quot;&quot;
      Return
   }
   
   NotActiveTarget =
   WinGetPos, X, Y, W, H, ahk_id %hTargetWin%
   if (X = XPrev &amp;&amp; Y = YPrev &amp;&amp; W = WPrev &amp;&amp; H = HPrev)
      Return
      
   NumPut(X + Border, RECT), NumPut(Y + Border + 22, RECT, 4)
   NumPut(X + W - Border, RECT, 8), NumPut(Y + H - Border, RECT, 12)
   DllCall(&quot;ClipCursor&quot;, UInt, &amp;RECT)
   
   XPrev := X, YPrev := Y, WPrev := W, HPrev := H
   Return
   
F11::
   if (switch := !switch)
   {
      SetTimer, WGP, Off
      DllCall(&quot;ClipCursor&quot;, UInt, 0)
   }
   Else
      SetTimer, WGP, On
   Return
   
Esc:: ExitApp

Exit:
   DllCall(&quot;ClipCursor&quot;, UInt, 0)
   ExitApp</code></pre></div><div class="quotebox"><cite>InFlames пишет:</cite><blockquote><p>К верхней границе прибавил 22 пикселя, что бы курсор перемещался только в рамках рабочей области, а границы не затрагивал.</p></blockquote></div><p>Может, нужна клиентская область окна — всё кроме строки заголовка, строки меню и окантовки? Если да, то можно точно определить её границы, без всяких прибавлений с помощью функции <em>GetWindowInfo</em>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-01-05T23:52:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43346#p43346</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43345#p43345" />
			<content type="html"><![CDATA[<p>Понемногу начинаю разбираться в этих функциях WinAPI, но всё понять не могу.</p><p>В строке <br /></p><div class="codebox"><pre><code>NumPut(X + Border, RECT), NumPut(Y + Border, RECT, 4)</code></pre></div><p>К верхней границе прибавил 22 пикселя, что бы курсор перемещался только в рамках рабочей области, а границы не затрагивал.<br /></p><div class="codebox"><pre><code>NumPut(X + Border, RECT), NumPut(Y + Border + 22, RECT, 4)</code></pre></div><p>Пусть теперь невозможно перетащить окно, но мне оно и не надо, главное, что бы курсор находился в рабочей области окна.</p><p>Еще вопрос, можно ли сделать так:<br />1. Запустили скрипт (с замененной строкой +22) - курсор находится в рабочей области экрана.<br />2. Сделать альт-таб, что бы окно стало неактивным.<br />3. Перетащить окно за заголовок (обычный способ перетаскивания окон), не активируя окна<br />4. Активировать окно, нажав ЛКМ по рабочей области окна&nbsp; (не по границам или заголовкам)<br />5. Опять альт-таб<br />6. Пока окно неактивно иметь возможность нажать на крестик, что бы закрыть окно.</p><p>Проще говоря, что бы при неактивном окне, кликая по заголовку или хватаясь за границы окна, что бы его растянуть, окно не активировалось. А активировалось в том случае, когда нажимаю ЛКМ в рабочую область.</p><p>Если такие запросы невыполнимы или чрезмерно надоедливы так и напишите <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2011-01-05T23:15:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43345#p43345</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43343#p43343" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>InFlames пишет:</cite><blockquote><p>при этом курсор удерживался бы именно внутри области окна, не заезжая на границы окна, которые позволяют его расягивать.</p></blockquote></div><p>По второму алгоритму для блокнота:<br /></p><div class="codebox"><pre><code>   OnExit, Exit
   
   Run, notepad.exe,,, PID
   WinWait, ahk_pid %PID%
   WinGet, hTargetWin, ID, ahk_pid %PID%
   
   VarSetCapacity(WI, 56)
   DllCall(&quot;GetWindowInfo&quot;, UInt, hTargetWin, UInt, &amp;WI)
   WBorder := NumGet(WI, 48)
   HBorder := NumGet(WI, 52)
   Border := WBorder &gt; HBorder ? WBorder : HBorder
   
   VarSetCapacity(RECT, 16)
   SetTimer, WGP, 10
   Return

WGP:
   if !WinExist(&quot;ahk_id &quot; hTargetWin)
      ExitApp
      
   WinGet, AID, ID, A
   if (AID != hTargetWin)
   {
      if !NotActiveTarget
         DllCall(&quot;ClipCursor&quot;, UInt, 0), NotActiveTarget := 1, XPrev := &quot;&quot;
      Return
   }
   
   NotActiveTarget =
   WinGetPos, X, Y, W, H, ahk_id %hTargetWin%
   NumPut(X + Border, RECT), NumPut(Y + Border, RECT, 4)
   NumPut(X + W - Border, RECT, 8), NumPut(Y + H - Border, RECT, 12)
   DllCall(&quot;ClipCursor&quot;, UInt, &amp;RECT)
   
   XPrev := X, YPrev := Y, WPrev := W, HPrev := H
   Return
   
Esc:: ExitApp

Exit:
   DllCall(&quot;ClipCursor&quot;, UInt, 0)
   ExitApp</code></pre></div><p>Окно можно двигать за строку заголовка. Можно переключать активное окно с помощью Alt + Tab. При этом курсор высвобождается, при обратном переключении снова клипируется. При закрытии целевого окна скрипт завершается, высвобождая курсор.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-01-05T21:28:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43343#p43343</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43334#p43334" />
			<content type="html"><![CDATA[<p>Windows 7. Эта галка у меня не стояла. Включение/выключение этой опции никакого эффекта не дало.<br />Отскакивает только от левого и верхнего края окна.</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2011-01-05T16:52:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43334#p43334</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43331#p43331" />
			<content type="html"><![CDATA[<p>Отскакивает, похоже, просто при очень быстром движении, даже не доходя до края окна, от пустого места.</p><p>В настройках мыши (в ХР) есть галочка &quot;Включить повышенную точность установки указателя&quot;. Вот когда я её убрал, отскоки прекратились. И что интересно — когда поставил обратно, они не вернулись. Даже перезагрузился для верности — не отскакивает. Больше вроде не менял ничего, так что странно.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2011-01-05T14:51:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43331#p43331</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43330#p43330" />
			<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>2011-01-05T14:19:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43330#p43330</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: удерживание курсора мыши в определенном окне]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43329#p43329" />
			<content type="html"><![CDATA[<p>У меня не отскакивает, ей-богу! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Даже не понимаю, как такое может получаться, исходя из логики получения координат:<br /></p><div class="codebox"><pre><code>   x := x &lt; XW ? XW : x &gt; XW + WW ? XW + WW : x
   y := y &lt; YW ? YW : y &gt; YW + HW ? YW + HW : y</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-01-05T13:59:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43329#p43329</id>
		</entry>
</feed>
