Same key but multiple functions

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hazixd
Posts: 4
Joined: 26 May 2022, 21:47

Same key but multiple functions

Post by Hazixd » 26 May 2022, 21:59

Hi I'm trying to make an ahk script but I'm pretty new which got me lost. The script should work like this, when I press the 1 key it should press the number 4, sleep 607, then right click. but then the second time i press the 1 key it should right click first, then press the number 4 (without sleep). The new script should either be able to keep count of the number of times ive pressed 1 and so applies the second function for all even numbers. or it could be in an orderly way where the first function would happen first, then the second when i press 1 again, then return back to the start. Thanks, also here's my current script which doesnt have the two functions.

Code: Select all

1::
Send 4
sleep 607
click right
Return

*=::
   ExitApp

Rohwedder
Posts: 7558
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Same key but multiple functions

Post by Rohwedder » 26 May 2022, 23:35

Hallo,
try:

Code: Select all

1::
IF odd_numbered := !odd_numbered
{
	Send 4
	sleep 607
	click right
}
Else ; even_numbered
{
	click right
	Send 4
}
Return
*=::ExitApp

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Same key but multiple functions

Post by BoBo » 26 May 2022, 23:47

Code: Select all

i := 2

1::
   if (mod(i,2)=0) ? even() : odd()
   i++
   return

odd() {
   send 4
   sleep 607
   click R
   }

even() {
   click R
   send 4
   }
   
*=::ExitApp

Hazixd
Posts: 4
Joined: 26 May 2022, 21:47

Re: Same key but multiple functions

Post by Hazixd » 26 May 2022, 23:59

Rohwedder wrote:
26 May 2022, 23:35
Hallo,
try:

Code: Select all

1::
IF odd_numbered := !odd_numbered
{
	Send 4
	sleep 607
	click right
}
Else ; even_numbered
{
	click right
	Send 4
}
Return
*=::ExitApp
hi it seems that theres a lot of errors with this one, first it said unexpected "}", which i fixed but then it said error "Else"

Hazixd
Posts: 4
Joined: 26 May 2022, 21:47

Re: Same key but multiple functions

Post by Hazixd » 27 May 2022, 00:02

Rohwedder wrote:
26 May 2022, 23:35
Hallo,
try:

Code: Select all

1::
IF odd_numbered := !odd_numbered
{
	Send 4
	sleep 607
	click right
}
Else ; even_numbered
{
	click right
	Send 4
}
Return
*=::ExitApp
i previously said something about errors but i pasted it incorrectly, my bad. this works thanks a lot

Post Reply

Return to “Ask for Help (v1)”