Settimer function is getting synced with other set timer function in the script. Also problem with blockinput function Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ulfric Stormcloak
Posts: 39
Joined: 28 Apr 2017, 23:26

Settimer function is getting synced with other set timer function in the script. Also problem with blockinput function

26 May 2017, 02:37

My script basically press the key 3,4 and 5 every 4, 20 and 18 seconds. The problem i have is sometimes the 4th second and 20th second or 18th second occur at the same time. Hence the script press the keys really fast.
I dont want it to do that. I want a at least a 1 second delay before the next button is pressed if 4th and 20th or 18th second occurs at the same.

Also the second problem i have is. I want the script to ignore all other input when it is time to press the button. I have tired the blockinput function but it doesnt work correctly for me. For example if i am holding down the W button and the blockinput command comes on the W button stays pressed forever which is really weird and i dont know what to do about that. So is their another function like blockinput.

Please use an example or edit on my script because i am really new to using AHK.

Thank you

Code: Select all

z::
RepeatKey := !RepeatKey
If RepeatKey
{
	SetTimer, SendTheKey1, 4000
	SetTimer, SendTheKey3, 20000
	SetTimer, SendTheKey2, 18000
}
Else
{
	SetTimer, SendTheKey1, Off
	SetTimer, SendTheKey3, Off
	SetTimer, SendTheKey2, Off
}
Return

SendTheKey1:
	SendInput 4
Return

SendTheKey3:
	SendInput 3
	sleep 800
Return

SendTheKey2:
	SendInput 5
	sleep 800
Return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi

26 May 2017, 03:06

You could create a queue. Then have the keys enter the queue at the exact time respectively, and implement a Queue-Manager to work through the queue one key at a time.
(The queue should be "first in, first out")

I'm not sure about your second question, but I think BlockInput works differently on Win7. Do you use Win7? If so, try running your script with admin privileges.
Ulfric Stormcloak
Posts: 39
Joined: 28 Apr 2017, 23:26

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi

26 May 2017, 03:20

wolf_II wrote:You could create a queue. Then have the keys enter the queue at the exact time respectively, and implement a Queue-Manager to work through the queue one key at a time.
(The queue should be "first in, first out")

I'm not sure about your second question, but I think BlockInput works differently on Win7. Do you use Win7? If so, try running your script with admin privileges.
I use windows 10 and yes i run the script as admin.

How would i be able to add a queue in my script ?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi

26 May 2017, 03:39

Re: Queue
I would start by making an "interface" (wrong word?) like so:

Code: Select all

/* test
MyQueue := Array()
FIFO_Push(    9, MyQueue)
FIFO_Push(  "-", MyQueue)
FIFO_Push(   77, MyQueue)
FIFO_Push(   "", MyQueue)
FIFO_Push("xyz", MyQueue)

While FIFO_Len(MyQueue)
    MsgBox, % "Len " FIFO_Len(MyQueue) "`nPop " FIFO_Pop(MyQueue)
*/


;-------------------------------------------------------------------------------
FIFO_Len(ByRef Queue) { ; return the number of items in Queue
;-------------------------------------------------------------------------------
    Return, Queue.Length()
}


;-------------------------------------------------------------------------------
FIFO_Push(Item, ByRef Queue) { ; append an item to Queue
;-------------------------------------------------------------------------------
    Queue.Push(Item)
}


;-------------------------------------------------------------------------------
FIFO_Pop(ByRef Queue) { ; pop first item from Queue
;-------------------------------------------------------------------------------
    Return, Queue.RemoveAt(1)
}


;-------------------------------------------------------------------------------
FIFO_isEmpty(ByRef Queue) { ; return true when Queue is empty
;-------------------------------------------------------------------------------
    Return, Queue.Length() = 0
}
Take a minute to look at this, and you will notice that my silly interface is just a roundabout way to replace one-line commands with other one-line commands.
BUT, I introduce an easy-to-work-with tool that might be worth the effort.
Ulfric Stormcloak
Posts: 39
Joined: 28 Apr 2017, 23:26

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi

26 May 2017, 03:45

wolf_II wrote:Re: Queue
I would start by making an "interface" (wrong word?) like so:

Code: Select all

/* test
MyQueue := Array()
FIFO_Push(    9, MyQueue)
FIFO_Push(  "-", MyQueue)
FIFO_Push(   77, MyQueue)
FIFO_Push(   "", MyQueue)
FIFO_Push("xyz", MyQueue)

While FIFO_Len(MyQueue)
    MsgBox, % "Len " FIFO_Len(MyQueue) "`nPop " FIFO_Pop(MyQueue)
*/


;-------------------------------------------------------------------------------
FIFO_Len(ByRef Queue) { ; return the number of items in Queue
;-------------------------------------------------------------------------------
    Return, Queue.Length()
}


;-------------------------------------------------------------------------------
FIFO_Push(Item, ByRef Queue) { ; append an item to Queue
;-------------------------------------------------------------------------------
    Queue.Push(Item)
}


;-------------------------------------------------------------------------------
FIFO_Pop(ByRef Queue) { ; pop first item from Queue
;-------------------------------------------------------------------------------
    Return, Queue.RemoveAt(1)
}


;-------------------------------------------------------------------------------
FIFO_isEmpty(ByRef Queue) { ; return true when Queue is empty
;-------------------------------------------------------------------------------
    Return, Queue.Length() = 0
}
Take a minute to look at this, and you will notice that my silly interface is just a roundabout way to replace one-line commands with other one-line commands.
BUT, I introduce an easy-to-work-with tool that might be worth the effort.
I am sorry i dont understand this. It looks really complicated, how would i be able to incorporate this into my script.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi  Topic is solved

26 May 2017, 04:02

First, save the code from my previous post as FIFO.ahk in the same folder as your script.

Then try this:

Code: Select all

#Include, FIFO.ahk

MyQueue := Array()
SetTimer, QueueManager, 1000
Return


;-------------------------------------------------------------------------------
QueueManager: ; runs once every second
;-------------------------------------------------------------------------------
    Send, % FIFO_Pop(MyQueue)
Return


;-------------------------------------------------------------------------------
z:: ; hotkey
;-------------------------------------------------------------------------------
    If (RepeatKeys := !RepeatKeys) {
        SetTimer, SendTheKey1,  4000
        SetTimer, SendTheKey2, 18000
        SetTimer, SendTheKey3, 20000
    }

    Else {
        SetTimer, SendTheKey1, Off
        SetTimer, SendTheKey2, Off
        SetTimer, SendTheKey3, Off
    }
Return


SendTheKey1:
	FIFO_Push(4, MyQueue)
Return


SendTheKey2:
	FIFO_Push(5, MyQueue)
Return


SendTheKey3:
	FIFO_Push(3, MyQueue)
Return
I hope that helps. (Not fully tested yet!)
Ulfric Stormcloak
Posts: 39
Joined: 28 Apr 2017, 23:26

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi

26 May 2017, 04:26

wolf_II wrote:First, save the code from my previous post as FIFO.ahk in the same folder as your script.

Then try this:

Code: Select all

#Include, FIFO.ahk

MyQueue := Array()
SetTimer, QueueManager, 1000
Return


;-------------------------------------------------------------------------------
QueueManager: ; runs once every second
;-------------------------------------------------------------------------------
    Send, % FIFO_Pop(MyQueue)
Return


;-------------------------------------------------------------------------------
z:: ; hotkey
;-------------------------------------------------------------------------------
    If (RepeatKeys := !RepeatKeys) {
        SetTimer, SendTheKey1,  4000
        SetTimer, SendTheKey2, 18000
        SetTimer, SendTheKey3, 20000
    }

    Else {
        SetTimer, SendTheKey1, Off
        SetTimer, SendTheKey2, Off
        SetTimer, SendTheKey3, Off
    }
Return


SendTheKey1:
	FIFO_Push(4, MyQueue)
Return


SendTheKey2:
	FIFO_Push(5, MyQueue)
Return


SendTheKey3:
	FIFO_Push(3, MyQueue)
Return
I hope that helps. (Not fully tested yet!)
Thanks will test this out
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Settimer function is getting synced with other set timer function in the script. Also problem with blockinput functi

26 May 2017, 05:09

Hmm, I thought about this some more, and the FIFO interface may be slightly on the side of overkill. The script can be simplified like so:
  • no more need to include anything
  • renamed SendTheKey to PushTheKey to clarify that Send is only done by the queue manager

Code: Select all

MyQueue := Array()
SetTimer, QueueManager, 1000
Return


;-------------------------------------------------------------------------------
QueueManager: ; runs once every second
;-------------------------------------------------------------------------------
    Send, % MyQueue.RemoveAt(1)
Return


;-------------------------------------------------------------------------------
z:: ; hotkey
;-------------------------------------------------------------------------------
    If (RepeatKeys := !RepeatKeys) {
        SetTimer, PushTheKey1,  4000
        SetTimer, PushTheKey2, 18000
        SetTimer, PushTheKey3, 20000
    }

    Else {
        SetTimer, PushTheKey1, Off
        SetTimer, PushTheKey2, Off
        SetTimer, PushTheKey3, Off
    }
Return


PushTheKey1:
	MyQueue.Push(4)
Return


PushTheKey2:
	MyQueue.Push(5)
Return


PushTheKey3:
	MyQueue.Push(3)
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], MiM, ntepa, supplementfacts and 144 guests