Ligar com um click, desligar com outro click Topic is solved

Tire suas dúvidas sobre programação em AutoHotkey

Moderator: Gio

marcosrob
Posts: 4
Joined: 16 Jun 2021, 14:36

Ligar com um click, desligar com outro click

Post by marcosrob » 16 Jun 2021, 14:47

Boa tarde.
Estou tentando fazendo um macro de no recoil, quero que ele ative quando der um click com botão direito e desative quando der outro click com mesmo botão.
O primeiro click funciona, mas quando clico novamente com botão direito nada faz.
Como fazer para reconhecer o segundo click e parar a repetição?
Obrigado.

Code: Select all

#NoEnv
SendMode Input
F1::ExitApp ; F1 used to exit the ahk script file
F2::Pause ; F2 pause

~RButton::
click := 0
if GetKeyState("RButton", "P")
{
	while (click = 0)
	{
		_auto := true ;Toggle for the anti-recoil being on or off. default is on
		~LButton::autofire() ; When the LButton is pressed run the autofire() function
		!LButton::_auto := ! _auto ;Alt + F2 used to toggle the anti-recoil on and off

		; autofire() function, name is misleading could easily be antiRecoil()
		autofire()
		{
			global _auto
			if _auto ; if _auto == true. i.e. is anti-recoil on?
				{ ; anti-recoil on? If yes do this
					Loop ; Continuously loop until a 'break' command
				{
		if GetKeyState("LButton", "P") ; If LButton is pressed
			{ ; LButton pressed? If yes do this
				Sleep 75 ; sleep for 75 milliseconds
				mouseXY(0,-15) ;Call the mouseXY() function which moves the mouse the specified distance. mouseXY( X, Y,)
				Sleep 45 ; sleep for 45 milliseconds
			}
		else ;LButton pressed? If no do this, i.e. exit the loop
			break ;will stop the loop
			} ;; loop
			} ;; if
			} ;; autofire() ; anti-recoil on? If no do nothing
		mouseXY(x,y)
		{
			DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0) ; moves the mouse could easily be the built in autohotkey MouseMove, X, Y
		}
	}	

}
[Mod edit: [code][/code] tags added.]
DoriTos_
Posts: 16
Joined: 15 Mar 2021, 08:30

Re: Ligar com um click, desligar com outro click  Topic is solved

Post by DoriTos_ » 18 Jun 2021, 16:34

Code: Select all

#SingleInstance, Force
#NoEnv
SendMode Input
F1::ExitApp ; F1 used to exit the ahk script file
F2::Pause ; F2 pause
#MaxThreadsPerHotkey 2

~RButton::
    Toggle := !Toggle
    If( Toggle )
        Loop {
            Sleep 75 ; sleep for 75 milliseconds
            mouseXY(0,-15) ;Call the mouseXY() function which moves the mouse the specified distance. mouseXY( X, Y,)
            Sleep 45 ; sleep for 45 milliseconds
        } Until ( !Toggle )
Return

mouseXY(x,y) {
    DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0) ; moves the mouse could easily be the built in autohotkey MouseMove, X, Y
}
Post Reply

Return to “Ajuda e Suporte Geral”