<?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=16004&amp;type=atom" />
	<updated>2021-01-21T17:33:18Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16004</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145168#p145168" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>BlackCat пишет:</cite><blockquote><p>Мне просто хотелось бы разобраться и понять</p></blockquote></div><p>Но вы же не хотите делать, что вам советуют.<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Пока оставьте в покое WinMove, добейтесь нормальной работы примера, который я привел.</p></blockquote></div><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Таймер с самого начала можно запускать только на один раз, почитайте справку.</p></blockquote></div><p>Зачем тогда спрашиваете?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-21T17:33:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145168#p145168</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145165#p145165" />
			<content type="html"><![CDATA[<p><strong>BlackCat</strong></p><p>Я бы так сделал. Правда с клавишей Альт.</p><div class="codebox"><pre><code>WinGetPos,,,, TaskBarHeight, ahk_class Shell_TrayWnd
ScreenHeight := A_ScreenHeight-TaskBarHeight+7
ScreenWidth := A_ScreenWidth


; Многократное нажатие:
#If (Win = 1)
~Alt &amp; NumpadAdd Up:: Counter++
#If

!NumpadAdd::
Counter := 0, Win := 1
KeyWait, Alt, U
Win =

Action:
If (Counter = 1)
 WinMove A,,,, ScreenWidth/1.1, ScreenHeight/1.1

Else If (Counter = 2)
 WinMove A,,,, ScreenWidth/1.2, ScreenHeight/1.2

Else If (Counter = 3)
 WinMove A,,,, ScreenWidth/1.4, ScreenHeight/1.4
Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2021-01-21T17:22:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145165#p145165</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145152#p145152" />
			<content type="html"><![CDATA[<p><strong>ypppu</strong><br />Мне просто хотелось бы разобраться и понять, почему в моем варианте после выполнения этой части<br /></p><div class="codebox"><pre><code>#NumpadAdd::
	; Удержание клавиши
	Keywait NumpadAdd, T0.5
	If (ErrorLevel) {
		WinMove A,,,, ScreenWidth/1.8, ScreenHeight/1.08
		Return
		}</code></pre></div><p>происходит выполнение части кода многократного нажатия, хотя здесь стоит Return<br />Т.е., эта часть кода срабатывает, но после отпускания удерживаемой клавиши, выполняется часть кода<br /></p><div class="codebox"><pre><code>	If (Counter = 1) {
		WinMove A,,,, ScreenWidth/1.1, ScreenHeight/1.1
		}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2021-01-21T14:13:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145152#p145152</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145151#p145151" />
			<content type="html"><![CDATA[<p>Похожая тема <a href="http://forum.script-coding.com/viewtopic.php?id=1205">AHK: Многодельность клавиши</a>.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2021-01-21T13:32:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145151#p145151</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145138#p145138" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Сделал теперь так:<br /></p><div class="codebox"><pre><code>#NumpadAdd::
	; Многократное нажатие
	Counter++
	SetTimer Action, 777
	Return
	
Action:
	If (Counter = 1) {
		WinMove A,,,, ScreenWidth/1.1, ScreenHeight/1.1
		}
	Else If (Counter = 2) {
		WinMove A,,,, ScreenWidth/1.2, ScreenHeight/1.2
		}
	Else If (Counter = 3) {
		WinMove A,,,, ScreenWidth/1.4, ScreenHeight/1.4
		}
	SetTimer Action, Off
	Counter := 0
Return</code></pre></div><p>В этом куске больше ничего не могу найти, вроде работает нормально.<br />Подскажите, плз, куда копать теперь, чтобы после отпускания клавиши на удержание не выполнялся код многократного нажатия?</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2021-01-21T08:38:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145138#p145138</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145137#p145137" />
			<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-01-21T07:33:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145137#p145137</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145136#p145136" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Ага, одну ошибку нашел.<br />Теперь сделал так (самый конец скрипта):<br /></p><div class="codebox"><pre><code>	Else If (Counter = 3) {
		WinMove A,,,, ScreenWidth/1.4, ScreenHeight/1.4
		}
	SetTimer Action, Off
	Counter := 0
Return</code></pre></div><p>Все верно?</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2021-01-21T07:30:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145136#p145136</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145135#p145135" />
			<content type="html"><![CDATA[<p>Можно, только немного посоображать нужно. Пока оставьте в покое WinMove, добейтесь нормальной работы примера, который я привел.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-21T07:08:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145135#p145135</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145134#p145134" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Что-то я не совсем понял.<br />Точнее - понял, что ничего не понял.<br />Счетчик работает в части многократного нажатия.<br />Сбой происходит в части удерживания кнопки - несмотря на Return иногда происходит выполнение части кода<br /></p><div class="codebox"><pre><code>	If (Counter = 1) {
		WinMove A,,,, ScreenWidth/1.1, ScreenHeight/1.1
		}</code></pre></div><p>Т.е., функция удерживания работает нормально, но иногда после отпускания клавиши выполняется этот кусок кода, который относится к многократному нажатию.</p><p>Можно по-подробнее, пожалуйста.<br />Может вообще невозможно посадить на одну кнопку функции многократного нажатия и удерживания?</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2021-01-21T06:39:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145134#p145134</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145129#p145129" />
			<content type="html"><![CDATA[<p>Прошу прощения. Не заметил &quot;Return&quot; в первом условии.</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2021-01-21T04:26:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145129#p145129</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145112#p145112" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>KusochekDobra пишет:</cite><blockquote><p>происходит безусловное увеличение &quot;Counter&quot; на единицу, независимо от того, удерживается клавиша &quot;NumpadAdd&quot;, или нажимается многократно</p></blockquote></div><p>Вообще-то нет, там Return в случае, когда выполняется действие по удержанию.<br /></p><div class="quotebox"><cite>BlackCat пишет:</cite><blockquote><p>Что я делаю не так?</p></blockquote></div><p>Во-первых, таймер запускаете, только если Counter = 1, во-вторых, у вас таймер после запуска метки продолжает выполняться, то-есть метка будет выполняться бесконечно. Проверить можно так:<br /></p><div class="codebox"><pre><code>#NumpadAdd::
   ; Действие по удержанию клавиши
   Keywait NumpadAdd, T0.2
   If (ErrorLevel) {
      SoundBeep 900
      Return
      }
      
   ; Многократное нажатие
   Counter++
   If (Counter = 1) {
      SetTimer Action, 777
      }
Return

Action:
   If (Counter = 1) {
      SoundBeep 400
      }
   Else If (Counter = 2) {
      SoundBeep 600
      }
   Else If (Counter = 3) {
      SoundBeep 800
      }
   Counter := 0
   SoundBeep 400
Return </code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-20T20:41:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145112#p145112</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145111#p145111" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>KusochekDobra пишет:</cite><blockquote><p>происходит безусловное увеличение &quot;Counter&quot; на единицу</p></blockquote></div><p>Возможно именно это.<br />Как Вы поняли, данный скрипт изменяет размеры активного окна и после удержания клавиши иногда происходит незапланированное выполнение блока<br /></p><div class="codebox"><pre><code>If (Counter = 1)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2021-01-20T20:25:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145111#p145111</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145110#p145110" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>BlackCat пишет:</cite><blockquote><p>... второй иногда работает не так, как должно</p></blockquote></div><p>А как должно?</p><p>Как минимум, происходит безусловное увеличение &quot;Counter&quot; на единицу, независимо от того, удерживается клавиша &quot;NumpadAdd&quot;, или нажимается многократно, что заставляет выполниться первый &quot;If&quot; в &quot;Action&quot;, а за тем, так же, безусловно происходит обнуление &quot;Counter&quot;, в следствии чего, ей никогда не стать больше единицы.</p><p>Последняя фигурная скобка должна закрываться на том же уровне индентации, где начинается объявление инструкций, тело которых она содержит. У Вас она на один таб дальше, что сбивает с толку, так как она кажется вложенной из-за этого.</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2021-01-20T20:15:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145110#p145110</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Действия по многократному нажатию или удержанию одной клавиши]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=145108#p145108" />
			<content type="html"><![CDATA[<p>Всем доброго времени!<br />Хотелось бы повесить выполнение различных команд на одной клавише, которые будут выполняются по многократному нажатию клавиши или ее удержанию.<br />По-отдельности куски кода работают нормально:<br /></p><div class="codebox"><pre><code>#NumpadAdd::
	; Действие по удержанию клавиши
	Keywait NumpadAdd, T0.2
	If (ErrorLevel) {
		WinMove A,,,, ScreenWidth/1.6, ScreenHeight/1.05
		Return
		}</code></pre></div><p>Но при совмещении двух кусков кода второй иногда работает не так, как должно:<br /></p><div class="codebox"><pre><code>WinGetPos,,,, TaskBarHeight, ahk_class Shell_TrayWnd
ScreenHeight := A_ScreenHeight-TaskBarHeight+7
ScreenWidth := A_ScreenWidth

#NumpadAdd::
	; Действие по удержанию клавиши
	Keywait NumpadAdd, T0.2
	If (ErrorLevel) {
		WinMove A,,,, ScreenWidth/1.6, ScreenHeight/1.05
		Return
		}
		
	; Многократное нажатие
	Counter++
	If (Counter = 1) {
		SetTimer Action, 777
		}
Return

Action:
	If (Counter = 1) {
		WinMove A,,,, ScreenWidth/1.1, ScreenHeight/1.1
		}
	Else If (Counter = 2) {
		WinMove A,,,, ScreenWidth/1.2, ScreenHeight/1.2
		}
	Else If (Counter = 3) {
		WinMove A,,,, ScreenWidth/1.4, ScreenHeight/1.4
		}
	Counter := 0
Return</code></pre></div><p>Что я делаю не так?</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2021-01-20T19:33:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=145108#p145108</id>
		</entry>
</feed>
