Toggle Script Not Working (Warning: Non-Coder)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Toggle Script Not Working (Warning: Non-Coder)

20 Apr 2017, 08:13

Hi. I am trying to have a toggle function using WheelUp and WheelDo


The following script is the best I can come up with so far, and just does nothing. Please help.
Last edited by blad4 on 30 Apr 2017, 15:25, edited 1 time in total.
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Toggle Script Not Working (Warning: Non-Coder)

20 Apr 2017, 09:27

Well, for a non-coder, you have come up with some very clever syntax! I really like your use of ++index and --index in the if statements to create a bounded range for the value of index.

Looking it over, the only thing that jumps out at me is that I'm not sure why you made MessageList a two-dimensional array? Wouldn't it make more sense to just do static MessageLife := [1, 2, 3, 4] and then reference MessageList[Index]?

Also, SendMessage itself is kinda outside my area of expertise, but have you tested the SendMessage commands on their own to make sure they work as written?
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Toggle Script Not Working (Warning: Non-Coder)

20 Apr 2017, 09:30

I am not able to read excecly what you want to do. Let me get this clear, You want:
- Select a message number with the WheelUp and WheelDown.
- Send the message by pressing E and disable the WheelDown/Up hotkeys so they can be used normaly again?

I did not test your SendMessage command, the rest seems to work as I expect.
About the ‘sequence:’ label: This line is not doing anything at the moment, maybe this is the part where the code does something you don't want. What should be the function of the this label?
User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Toggle Script Not Working (Warning: Non-Coder)

20 Apr 2017, 12:01

Your sendmessage 3rd parameter is a 0 in the function and in your post you want it to be a 1?
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Toggle Script Not Working (Warning: Non-Coder)

21 Apr 2017, 01:32

MaxAstro wrote:Well, for a non-coder, you have come up with some very clever syntax! I really like your use of ++index and --index in the if statements to create a bounded range for the value of index.

Looking it over, the only thing that jumps out at me is that I'm not sure why you made MessageList a two-dimensional array? Wouldn't it make more sense to just do static MessageLife := [1, 2, 3, 4] and then reference MessageList[Index]?

Also, SendMessage itself is kinda outside my area of expertise, but have you tested the SendMessage commands on their own to make sure they work as written?
I take no credit whatsoever for any 'syntax' ! :) Thanks to the amazing people like kon, dyatactic et al I just cut and paste things together. They are the clever coders here!
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Toggle Script Not Working (Warning: Non-Coder)

21 Apr 2017, 02:03

Xtra wrote:Your sendmessage 3rd parameter is a 0 in the function and in your post you want it to be a 1?
Thank you, correct! I'm not sure why it is a 0
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Toggle Script Not Working (Warning: Non-Coder)

21 Apr 2017, 02:06

DyaTactic wrote:I am not able to read excecly what you want to do. Let me get this clear, You want:
- Select a message number with the WheelUp and WheelDown.
- Send the message by pressing E and disable the WheelDown/Up hotkeys so they can be used normaly again?

I did not test your SendMessage command, the rest seems to work as I expect.
About the ‘sequence:’ label: This line is not doing anything at the moment, maybe this is the part where the code does something you don't want. What should be the function of the this label?
Yep so this was taken from a time script which had me interrupting the timer with a similar toggle. Now I am just trying to adapt it to a toggle only, with no timer function.

This is also linked to the pressing of E. In the original script E was pressed to begin the timer, aka sequence. Now it is not needed but I was reading the code as if E needs to still be pressed in order to activate the WheelUp/Down toggle!

So really all I want to do is what you said in the first point, which was 'Select a message number with the WheelUp and WheelDown.'

And this is always 1,2,3 or 4. If WheelDown then -1, if WheelUp then +1. If we are at 1, then -1 is 4. If we're at 4, then +1 is 1 etc
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Toggle Script Not Working (Warning: Non-Coder)

21 Apr 2017, 02:17

MaxAstro wrote:Well, for a non-coder, you have come up with some very clever syntax! I really like your use of ++index and --index in the if statements to create a bounded range for the value of index.

Looking it over, the only thing that jumps out at me is that I'm not sure why you made MessageList a two-dimensional array? Wouldn't it make more sense to just do static MessageLife := [1, 2, 3, 4] and then reference MessageList[Index]?

Also, SendMessage itself is kinda outside my area of expertise, but have you tested the SendMessage commands on their own to make sure they work as written?
Yep I use these SendMessage commands already so they work, luckily! Regarding the two-dimensional array, this must be because in the script I am cutting from, we had INdex 1 and Index 2. Therefore, is this what you mean?:

Code: Select all

static MessageList := [1, 2, 3, 4]
Is better than

Code: Select all

static MessageList := [[1], [2], [3], [4]]
?

Also I have utilised the WheelOnOff functions incorrectly, and now my #IfWinActive has stopped working. That is to say the hotkeys are working all over the place, regardless of which window is open.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Toggle Script Not Working (Warning: Non-Coder)

21 Apr 2017, 06:50

I have rewritten your code. Now pressing E toggles the ScrollWheelhotkeys On (they are already On on startup). You can select an Index (made a nice tooltip indicating which is selected) by scrolling. Press E again to Execute the SendMessage and disable the ScrollWheelhotkeys.
Pressing E again enables the scrollhotkeyskeys etc...

Is this what you seached for?

Code: Select all

index := 0
ToggleVar := 0

e::
	If ToggleVar
	{
		ToggleVar := 0
		WheelOnOff("Off")
		CustomMessage(++index)
	} Else {
		ToggleVar := 1
		WheelOnOff("On")
	}
Return

#If	; When using IfWinActive here, the hotkey commands in the function need this ‘Hotkey, IfWinActive’ command two.

WheelUp::
    if (++index > 3)	; Add one to Index and check it's upper boundry.
		index := 3
	ToolTip, % Index + 1
	SetTimer, ToolTipOff, -1000	; Hide the tooltip after 1000ms (minus means once, not again every second.)
	return

WheelDown::
    if (--index < 0)	; Substract one from Index and check it's bottom boundry.
        index := 0
	ToolTip, % Index + 1
	SetTimer, ToolTipOff, -1000	; Hide the tooltip after 1000ms (minus means once, not again every second.)
	return

ToolTipOff:
	ToolTip
	Return
	
WheelOnOff(State := "Off")
{
    Hotkey, WheelUp, %State%
    Hotkey, WheelDown, %State%
}

CustomMessage(Index)
{
    static MessageList := [[1], [2], [3], [4]]
    SendMessage, 0x1330, MessageList[Index, 1], 0, SysTabControl322, Sierra ;TCM_SETCURFOCUS = 0x1330
}
return
Personaly I would make pressing E enable the scrollkeys and releasing E execute the SendMessage with the index chosen when E was held down. Tell me if you need any help.
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Toggle Script Not Working (Warning: Non-Coder)

25 Apr 2017, 16:32

Thank you sir! What you wrote works fine except from when tooltip1 comes about and wheeldown is pressed, it does not go to 4. It just stays at one. And vice versa when trying to go from 4 to 1.
Last edited by blad4 on 30 Apr 2017, 15:26, edited 1 time in total.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Toggle Script Not Working (Warning: Non-Coder)

25 Apr 2017, 17:13

It took some time to get what you ment. It sounded like something was wrong in the script.
I belive this is the change you asked for: If (index = 1) > WheelDown > Index becomes 4
And If (Index = 4) > WheelDown > Index becomes 1
See if this script fills your needs.

Code: Select all

index := 0
ToggleVar := 0

WheelUp::
	if (++index > 3) ; Add one to Index and check it's upper boundry.
	index := 0
	ToolTip, % Index + 1
	SetTimer, ToolTipOff, -1000 ; Hide the tooltip after 1000ms (minus means once, not again every second.)
	return

WheelDown::
	if (--index < 0) ; Substract one from Index and check it's bottom boundry.
	index := 3
	ToolTip, % Index + 1
	SetTimer, ToolTipOff, -1000 ; Hide the tooltip after 1000ms (minus means once, not again every second.)
	return

ToolTipOff:
	ToolTip
	Return

WheelOnOff(State := "Off")
{
	Hotkey, WheelUp, %State%
	Hotkey, WheelDown, %State%
}

CustomMessage(Index)
{
	static MessageList := [[1], [2], [3], [4]]
	SendMessage, 0x1330, MessageList[Index, 1], 0, SysTabControl322, Sierra ;TCM_SETCURFOCUS = 0x1330
}
return
With the ‘#IfWinActive’ version you need a button or other condition on which to send the message. This could be the ToolTipOff label I see now.
blad4
Posts: 307
Joined: 07 Oct 2015, 11:06

Re: Toggle Script Not Working (Warning: Non-Coder)

26 Apr 2017, 18:24

Thanks so much man!

(And for the last one too :D )

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bubo_Bubo, Google [Bot], mikeyww, OrangeCat, RussF and 122 guests