Timer controlled input in loop

Get help with using AutoHotkey and its commands and hotkeys
bloxi10
Posts: 2
Joined: 20 Jun 2018, 09:28

Timer controlled input in loop

20 Jun 2018, 10:31

Hi,

Im trying to make a macro which continuously sends an input while a key is pressed in my case "Z", and repeatedly sends the input X. This is easily done but what I want to do now is have another key "U" be input at every 1000ms and Im confused on how to do this second part. I tried another approach instead of continuous input of X, having just 2 inputs exactly when I need them and then sending U, but I don't fully understand how this loop is working. Because the behaviour currently is - while "Z" is pressed it continuously sends "X" and once "Z" is unpressed it then sends the remaining keys i.e. "X" then "U".

The behaviour I want is either Continuous input of "X" and one "U" every 1000ms whilst "Z" is pressed, OR one "X" followed by another "X" 500ms later followed by one "U" and these 3 inputs repeated whilst "Z" is pressed.

This is what I had when i tried the second approach -

Code: Select all

Random, rndSleep, 500, 550

$Z::
  While GetKeyState("Z","P")
    Send, {X}
	Sleep rndSleep
	Send, {X}
	Sleep 60
	Send, {U}

Return

F7::Suspend
Any help would be appreciated.
Rohwedder
Posts: 1439
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Timer controlled input in loop

20 Jun 2018, 11:17

Hallo;
perhaps:

Code: Select all

Random, rndSleep, 500, 550
$z::
SetTimer, SendU, 1000 ;every 1000ms
While GetKeyState("Z","P")
{
	Send, {X}
	Sleep rndSleep
	Send, {X}
	Sleep 60
}
SetTimer, SendU, Off
Return
SendU:
Send, {U}
Return
F7::Suspend
Hellbent
Posts: 143
Joined: 23 Sep 2017, 13:34

Re: Timer controlled input in loop

20 Jun 2018, 11:42

Here are two different metods


Code: Select all

#SingleInstance, Force
Random, rndSleep, 500, 550
return

Send_U(){
	send,u	
}

/*
$*Z::
	Start_Time:=A_Tickcount
	While(GetKeyState("Z","p")){
		Send,X
		Sleep rndSleep
		if(A_TickCount-Start_Time>=1000){
			Start_Time:=A_Tickcount
			Send,u
		}
	}
	Return
*/

;/*
$*Z::
	SetTimer,Send_U,1000
	While(GetKeyState("Z","p")){
		Send,X
		Sleep rndSleep
	}
	SetTimer,Send_U,Off
	Return
;*/


*^ESC::ExitApp
bloxi10
Posts: 2
Joined: 20 Jun 2018, 09:28

Re: Timer controlled input in loop

20 Jun 2018, 12:45

Thanks, SetTimer is what I was looking for.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Mipha, TheYllib and 124 guests