Random key after time or keypress

Ask gaming related questions (AHK v1.1 and older)
uyouz
Posts: 3
Joined: 01 Dec 2021, 07:11

Random key after time or keypress

Post by uyouz » 01 Dec 2021, 07:24

How to press a random key after a certain number of keypresses or after a certain time?

Code: Select all

#MaxThreadsPerHotkey 2
Var1 := 0
arr := ["w", "a", "s", "d"]
F11::
	toggle:=!toggle
	While toggle{
	  Send r
	  Var1++
	  Sleep 3500
	  if(Var1 = 5){
		Var1 := 0
		Random, oVar, 1, 4
        sendinput % arr[oVar]        <------- Percentage error
		return
		}
	}
Return

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Random key after time or keypress

Post by mikeyww » 01 Dec 2021, 11:50

I did not see any error messages.

uyouz
Posts: 3
Joined: 01 Dec 2021, 07:11

Re: Random key after time or keypress

Post by uyouz » 01 Dec 2021, 12:15

I dont use any ide. After you mention it, i copied this codes and i don't get either.

I was getting this error message.

Code: Select all

This parameter contains a variable name missing its ending percent sign.
One more issue: After if statement, codes stops working. How i fix that?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Random key after time or keypress

Post by mikeyww » 01 Dec 2021, 12:36

If you do not want the script to return from this subroutine-- which is when the subroutine ends-- then you would eliminate return (line 14).

Explained: Return

uyouz
Posts: 3
Joined: 01 Dec 2021, 07:11

Re: Random key after time or keypress

Post by uyouz » 01 Dec 2021, 12:52

Thank you. Its working very well now.

Post Reply

Return to “Gaming Help (v1)”