Same key for different functions. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vuki
Posts: 3
Joined: 17 Jan 2020, 05:11

Same key for different functions.

17 Jan 2020, 05:20

I'm trying to make one key do two different functions.
Ex.
When I press ^B:: SendInput test1
then when I press ^B:: SendInput test2
and I want it to loop sending test1 > test2 > test1 > test2 each time i press Ctrl B

Code: Select all

Number := 1

^B::
if (Number := 1) 
{
sendInput test
Number := Number - 1
}
if (Number := 0)
{
sendInput best
Number := Number + 1
}
return
I've also tried
Number -= 1
and I tried just telling it
If (Number :=1) {Number = 0}
And I tried with strings instead of numbers.
I know there's probably a better way than this, but I can't figure it out. Any help would be appreciated
User avatar
Hellbent
Posts: 2112
Joined: 23 Sep 2017, 13:34

Re: Same key for different functions.

17 Jan 2020, 05:26

Is this what you're going for?

Code: Select all


^B::
	SendInput,% "test" ((Tog:=!Tog)+1)
	return
or if you really need it to start at 1 you can do something like this.

Be sure to read the comment ;)

Code: Select all

^B::
This_Is_Being_Done_As_A_Function_To_Use_Static(){  ;but you could just put tog := 1 in the auto-execute section.
	static Tog := 1	
	SendInput,% "test" ((Tog:=!Tog)+1)
}
Last edited by Hellbent on 17 Jan 2020, 05:30, edited 1 time in total.
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: Same key for different functions.  Topic is solved

17 Jan 2020, 05:30

Code: Select all

toggle := true
~F1::toggle := !toggle   ; another key switch

#If toggle = "1"
^b::send test1
#If

#If toggle = "0"
^b::send test2
#If

;-------------------------

^s::    ;same key switch
    tog := !tog
    if tog
        send test1
    else
        send test2
    return
vuki
Posts: 3
Joined: 17 Jan 2020, 05:11

Re: Same key for different functions.

17 Jan 2020, 05:53

Hellbent wrote:
17 Jan 2020, 05:26
Is this what you're going for?

Code: Select all


^B::
	SendInput,% "test" ((Tog:=!Tog)+1)
	return
or if you really need it to start at 1 you can do something like this.

Be sure to read the comment ;)

Code: Select all

^B::
This_Is_Being_Done_As_A_Function_To_Use_Static(){  ;but you could just put tog := 1 in the auto-execute section.
	static Tog := 1	
	SendInput,% "test" ((Tog:=!Tog)+1)
}
This does work but I'm not sure how to add more functions to this toggle. I didn't ask my question correctly
vuki
Posts: 3
Joined: 17 Jan 2020, 05:11

Re: Same key for different functions.

17 Jan 2020, 06:00

Thank you both very much! I finally got it working :D :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], shipaddicted and 97 guests