Mouse wheel changing variable. Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Hajin
Posts: 48
Joined: 13 May 2016, 09:16

Mouse wheel changing variable.

05 Nov 2020, 17:18

I saw the program's help file a little but I didn't find an answer, I can't change the variable with the mouse wheel.
Below, attempts that did not work:

Code: Select all

SetTimer, Button_Pressed, 1
return

Button_Pressed:

	GetKeyState, state, WheelUp
	if state = D
	{
		var_a = 1
	}
	
	GetKeyState, state, WheelDown
	if state = D
	{
		var_a = 0
	}


	if (var_a = 1)
	{
		Send {LButton down}
		Sleep, 50
		Send {LButton up}
		Sleep, 50
	}
	else{}
	
return

F10::
{
	ExitApp
}

Code: Select all

SetTimer, Button_Pressed, 1
return

Button_Pressed:

	WheelUp::
	{
		var_a = 1
	}
	return
	
	WheelDown::
	{
		var_a = 0	
	}
	return
	
	if (var_a = 1)
	{
		Send {LButton down}
		Sleep, 50
		Send {LButton up}
		Sleep, 50
	}
	else{}
	
return

F10::
{
	ExitApp
}
User avatar
mikeyww
Posts: 5424
Joined: 09 Sep 2014, 18:38

Re: Mouse wheel changing variable.  Topic is solved

05 Nov 2020, 18:25

Code: Select all

Gosub, WheelDown
SetTimer, Check, 100
Check:
ToolTip, %status%
Return

WheelUp::
status = ON
SoundBeep, 1500, 20
Return

WheelDown::
status = OFF
SoundBeep, 1000, 20
Return
The timer is not actually needed here, because in this script, the only determinants of a status change are the wheel actions; therefore, those routines can directly handle any actions needed. If you had other routines also changing the same variable, then the timer might have some use. The following script illustrates this.

Code: Select all

GoSub, WheelDown

WheelUp::
status = ON
SoundBeep, 1500, 20
Gosub, Show
Return

WheelDown::
status = OFF
SoundBeep, 1000, 20
Show:
ToolTip, %status%
Return
User avatar
Hajin
Posts: 48
Joined: 13 May 2016, 09:16

Re: Mouse wheel changing variable.

05 Nov 2020, 18:52

mikeyww wrote:
05 Nov 2020, 18:25

Code: Select all

Gosub, WheelDown
SetTimer, Check, 100
Check:
ToolTip, %status%
Return

WheelUp::
status = ON
SoundBeep, 1500, 20
Return

WheelDown::
status = OFF
SoundBeep, 1000, 20
Return
The timer is not actually needed here, because in this script, the only determinants of a status change are the wheel actions; therefore, those routines can directly handle any actions needed. If you had other routines also changing the same variable, then the timer might have some use. The following script illustrates this.

Code: Select all

GoSub, WheelDown

WheelUp::
status = ON
SoundBeep, 1500, 20
Gosub, Show
Return

WheelDown::
status = OFF
SoundBeep, 1000, 20
Show:
ToolTip, %status%
Return

Thanks for the quick response, I saw that my script should be like this in my situation:

Code: Select all

SetTimer, Button_Pressed, 1
return

Button_Pressed:

	
	if (var_a = 1)
	{
		Send {a down}
		Sleep, 5
		Send {a up}
		Sleep, 5
	}
	else{}

return

WheelUp::
var_a = 1
return

WheelDown::
var_a = 0	
return

F10::
{
	ExitApp
}
This script shown is part of a more complex script.
User avatar
mikeyww
Posts: 5424
Joined: 09 Sep 2014, 18:38

Re: Mouse wheel changing variable.

05 Nov 2020, 19:07

Yes, that works. Here's another way to write it, in case it gives you ideas.

Code: Select all

SetTimer, Check, 1

WheelUp::var_a := True
WheelDown::var_a := False
F10::ExitApp

Check:
If !var_a
 Return
Send {a down}
Sleep, 5
Send {a up}
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: albertocv, boiler, braunbaer, Google [Bot], Xeo786 and 53 guests