How you'd setup multiple key triggers for different tasks? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
irobot335
Posts: 3
Joined: 08 Nov 2016, 02:47

How you'd setup multiple key triggers for different tasks?

08 Nov 2016, 03:56

Hi there, I'm looking to create a script that will allow you to press multiple keys to toggle activate a set of commands (press again to disable).

For example:

Pressing Ctrl+q (^q::) will make pressing the number keys 1,2,3,4,5 output "one","two","three","four","five" respectively.
If you pressed it again, these keys would function as normal keys.

Pressing Ctrl+e (^e::) will make pressing the number keys 1,2,3,4,5 output "six","seven","eight","nine","ten" respectively.
If you pressed it again, these keys would function as normal keys.


A shoddy example I whipped up

Code: Select all

//Task one
^q::
Suspend, Toggle
1:: Send "one" Return
2:: Send "two" Return
3:: Send "three" Return
4:: Send "four" Return
5:: Send "five" Return

//Task two
^e::
Suspend, Toggle
1:: Send "six" Return
2:: Send "seven" Return
3:: Send "eight" Return
4:: Send "nine" Return
5:: Send "ten" Return
I know this horrible pseudocode doesn't work AT ALL but hopefully it demonstrates my idea, any help would be greatly appreciated! Thanks
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: How you'd setup multiple key triggers for different tasks?  Topic is solved

08 Nov 2016, 05:01

Code: Select all

^q::
task1 := !task1
task2 := 0
return

^e::
task2 := !task2
task1 := 0
return

#if task1
1:: Send "one"
2:: Send "two"
3:: Send "three"
4:: Send "four"
5:: Send "five"
#If
	

#if task2
1:: Send "six"
2:: Send "seven"
3:: Send "eight"
4:: Send "nine"
5:: Send "ten"
#if
irobot335
Posts: 3
Joined: 08 Nov 2016, 02:47

Re: How you'd setup multiple key triggers for different tasks?

08 Nov 2016, 05:30

ahcahc wrote:

Code: Select all

^q::
task1 := !task1
task2 := 0
return

^e::
task2 := !task2
task1 := 0
return

#if task1
1:: Send "one"
2:: Send "two"
3:: Send "three"
4:: Send "four"
5:: Send "five"
#If
	

#if task2
1:: Send "six"
2:: Send "seven"
3:: Send "eight"
4:: Send "nine"
5:: Send "ten"
#if
Awesome! Thank you!

I hadn't even thought of using If statements, this is exactly what I was looking for, and i'm sure i'll be able to add extra modifiers easily too.

cheers
irobot335
Posts: 3
Joined: 08 Nov 2016, 02:47

Re: How you'd setup multiple key triggers for different tasks?

08 Nov 2016, 05:34

Also quick question, what designates the position of the return command? i.e, why is there a return under each of the hotkeys but not under the if statements?

Cheers
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: How you'd setup multiple key triggers for different tasks?

08 Nov 2016, 08:00

Return marks the end of the hotkey. #If is for context sensitive hotkeys, it enables the hotkeys if the conditions were met. #if without parameters marks the end of the conditional hotkeys.

https://autohotkey.com/docs/commands/Return.htm
https://autohotkey.com/docs/commands/_If.htm
https://autohotkey.com/docs/Hotkeys.htm

Return to “Ask For Help”

Who is online

Users browsing this forum: agathange, Bodhi, Google [Bot], hasantr, lluke, SKR and 52 guests