1

Тема: AHK: Loop залип*

Здравствуйте, не подскажите в чем может быть проблема(?)
Есть вроде бы простой скрипт:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#UseHook
#NoEnv
#Persistent
#KeyHistory, 0
#HotKeyInterval -1
#MaxHotkeysPerInterval 200
#InstallKeybdHook
#SingleInstance, Force
SetKeyDelay,  -1
SetMouseDelay, -1

#InstallMouseHook
SetBatchLines, -1
SetTimer, CheckKey, On
SetTimer, CheckKey, 1

*~LButton::
Loop ; Цикл
{
	Sleep, 5
	Send, {LButton}
	moveAmount := (moveAmount = 2) ? 3 : 0
	mouseXY(moveAmount,4.7)
	GetKeyState, state, LButton, P
	if state = U  ; Клавиша отпущена, поэтому выйти из цикла.
		break
}
mouseXY(x,y)
{
	DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}

KeyWait, LButton
Return

Беда в том что при нажатие LButton ИНОГДА скрипт не выходит из циклы и думает что LButton до сих пор в статусе "Нажата". Хотя кнопка мыши уже давно отпущена.

Есть еще один код написанный за долго до первого и в нем данной проблемы вроде бы нет. Вот он:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#NoEnv
SendMode Input

~F5::Suspend

~End::ExitApp

*~LButton::
Loop ; Цикл
{
	Sleep, 5
	moveAmount := (moveAmount = 2) ? 3 : 0
	mouseXY(moveAmount,4.5)
	GetKeyState, state, LButton, P
	if state = U  ; Клавиша отпущена, поэтому выйти из цикла.
		break
}
mouseXY(x,y)
{
	DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}

Структура вроде одна, но второй/этот скрипт не залипает в цикле...

В первом коде SetTimer не помог решить данную проблему. Не подскажите может быть в первом коде что-то лишнее имеется(?)
Спасибо!

2

Re: AHK: Loop залип*

Используйте цикл While вместо Loop.

3

Re: AHK: Loop залип*

stealzy на вряд ли в этом проблема так как имеется еще 1 код а точнее еще одна часть 1-ого кода где тоже происходит "залипание loop", но там бинд сам себя не отправляет. В общем вот как это выглядит вместе:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#UseHook
#NoEnv
#Persistent
#KeyHistory, 0
#HotKeyInterval -1
#MaxHotkeysPerInterval 200
#InstallKeybdHook
#SingleInstance, Force
SetKeyDelay,  -1
SetMouseDelay, -1

#InstallMouseHook
SetBatchLines, -1
SetTimer, CheckKey, On
SetTimer, CheckKey, 1

x1 := A_ScreenWidth // 100
y1 := A_ScreenHeight // 50
x2 := A_ScreenWidth // 2
y2 := A_ScreenHeight // 4

#If WinActive("ahk_class xxx")

*~MButton::
Send, {scF}
Sleep, 10 ; Задержка
Loop ; Цикл
{
	Sleep, 1
	MouseClickDrag, Left, %x1%, %y1%, %x2%, %y2% , 0 ; Передвижение мыши
	GetKeyState, state, MButton, P
	if state = U  ; Клавиша отпущена, поэтому выйти из цикла.
		break
}
Send, {scF} ; Закрыть инвентарь
KeyWait MButton
return


vk5B & vk52::return

vk5B::return

~F6::Suspend

*~End::ExitApp

CheckKey:
GetKeyState, state, LButton 
GetKeyState, state, MButton
Return


*~LButton::
Loop ; Цикл
{
	Sleep, 5
	Send, {LButton}
	moveAmount := (moveAmount = 2) ? 3 : 0
	mouseXY(moveAmount,4.7)
	GetKeyState, state, LButton, P
	if state = U  ; Клавиша отпущена, поэтому выйти из цикла.
		break
}
mouseXY(x,y)
{
	DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}
; _____________________________________________

KeyWait, LButton
Return
; _____________________________________________

*~XButton2::
Send, 2
Send, 1
Return

*XButton1::
Send, {LButton Down}
KeyWait, XButton1
Send, {LButton Up}
KeyWait, XButton1
Return

Оба лупа ИНОГДА зацикливаются. Хотя бинд уже отжат. И циклы не останавливаются пока бинд не будет повторно нажат.
SetTimer вообще не как не повлиял на код, даже если его значение равно 1.
Не могу понять в чем проблема.

4 (изменено: stealzy, 2018-09-06 19:48:07)

Re: AHK: Loop залип*

romzes96 пишет:

MouseClickDrag

Хрен редьки не слаще, Send / мышиным командам приходится отжимать зажатый вами LButton, который вы непонятно вообще с какой целью посылаете насквозь.
Либо не отправляйте нажатие самого хоткея насквозь, либо используйте аналоги мышиных команд через Send с опцией {Blind}.

5

Re: AHK: Loop залип*

Для чего нужна звёздочка перед биндом?
Что она выполняет? Не встречал раньше.


*~vk01::

6

Re: AHK: Loop залип*

slavafedora, почитайте тут (Rus/Eng).

AutoHotkey - 1.1.32.00