# Making a Queue

## Recommended Posts

Okay, so i have a C++ for Dummies book and it has a (Very) little information on Queue's, however I cant figure out how to translate that into Autoit. I've looked through all the Help File topics as well as the forums here, no luck.

I've read up on wiki, and I believe I understand them, But I couldn't find out how to do them in Autoit.

##### Share on other sites

Hi Ericnail,

There is a rather large difference from C++ to AutoIt. Maybe if you explain what you wish to achieve and then we can point you in the best direction.

Cheers,

Brett

##### Share on other sites

Okay, so i have a C++ for Dummies book and it has a (Very) little information on Queue's, however I cant figure out how to translate that into Autoit. I've looked through all the Help File topics as well as the forums here, no luck.

I've read up on wiki, and I believe I understand them, But I couldn't find out how to do them in Autoit.

If by a 'queue' you mean a FIFO buffer then you need to read up on arrays and understand how to use them. Then you can make a queue fairly easily. (Or a FILO and a lot of other things)

Here is a simple example.

```#include <array.au3>

for \$n = 1 to 20
pop(\$fifo1,\$n)
Next

for \$n = 1 to 20
ConsoleWrite(pull(\$fifo1) & @CRLF)
Next

Func Pop(ByRef \$aFifo,\$data)
\$aFifo[0] += 1; element 0 used for the number of entries

If UBound(\$aFifo) < \$aFifo[0] + 1 then
Redim \$aFifo[UBound(\$aFifo) + 20];grow by 20 at a time
EndIf

\$aFifo[\$aFifo[0]] = \$data
endfunc

Func Pull(ByRef \$aFifo)
If \$aFifo[0] = 0 then return SetError(0,-1)
Local \$result = \$aFifo[1]
_ArrayDelete(\$aFifo,1)
\$aFifo[0] -= 1
Return \$Result
EndFunc```
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
##### Share on other sites

Hi Ericnail,

There is a rather large difference from C++ to AutoIt. Maybe if you explain what you wish to achieve and then we can point you in the best direction.

Cheers,

Brett

Yeah, I learned that the hard way

Thanks Brett,

I am actually checking a 1-100%(Usage Amount) Variable on 4 Different Network Monitors. I am trying to set it up so that it will alert me if any of the Network Monitors has a drop of more that 30% in less than 3 Seconds.

So I need to record the Variable from the network monitor as well as the time-stamp into an Array and have about 8 Records for each second(8 checks a second) and I would like to put them into a FILO structure on a Circular Buffer so that it continues indefinitely. <-- And do this for each of the 4 Network Monitors..

~Eric

P.S. I have been trying to use the _ArrayPush UDF for the last Hour or so, but I'm thinking there's got to be an easier way.

Edited by ericnail
##### Share on other sites

Check this out:

You can use a "real" Queue instead.

```;==================================================================================================
; Name:      _ObjQueueCreate()
; Return:    Success:   Handle to the Queue-Object
;            Failure:  -1
;            @error:    1  Couldnt create Queue
;==================================================================================================
Func _ObjQueueCreate()
Local \$obj = ObjCreate("System.Collections.Queue")
If (Not IsObj(\$obj)) Then
Return SetError(1, 0, -1)
Else
Return \$obj
EndIf
EndFunc   ;==>_ObjQueueCreate

;==================================================================================================
; Parameter: \$ObjQueue - Handle to the Queue-Object
;            \$Value    - Value to add.
; Return:    Success   0
;            Failure:  -1
;        @error:   1  Object doesnt exist
;                  2  Value is empty
;                  3  Enqueue didnt work.
;==================================================================================================
Func _ObjQueueAdd(ByRef \$ObjQueue, \$VALUE = '')
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
If \$VALUE = '' Then Return SetError(2, 0, -1)
\$ObjQueue.Enqueue(\$VALUE)
If @error Then Return SetError(3, 0, -1)
Return 0

;==================================================================================================
; Name:      _ObjQueueSearch(\$ObjQueue, \$Value)
; Parameter: \$ObjQueue - Handle to the Queue-Object
;            \$Value    - Value to search
; Return:    Success   TRUE   Value exists
;                      FALSE  Value doesnt exist
;            Failure:  -1
;            @error:   1  Object doesnt exist
;                      2  Value is empty
;                      3  Error while object interaction
;==================================================================================================
Func _ObjQueueSearch(ByRef \$ObjQueue, \$VALUE = '')
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
If \$VALUE = '' Then Return SetError(2, 0, -1)
If \$ObjQueue.Contains(\$VALUE) Then
Return True
Else
Return False
EndIf
If @error Then Return SetError(3, 0, -1)
EndFunc   ;==>_ObjQueueSearch

;==================================================================================================
; Name:      _ObjQueueGetFirst(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   First value of the queue
;            Failure:  -1
;            @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueueGetFirst(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Peek
EndFunc   ;==>_ObjQueueGetFirst

;==================================================================================================
; Name:      _ObjQueuePopFirst(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   First Value of the Queue. It will also be deleted.
;            Failure:  -1
;            @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueuePopFirst(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Dequeue
EndFunc   ;==>_ObjQueuePopFirst

;==================================================================================================
; Name:      _ObjQueueCount(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   Amount of values in queue
;            Failure:  -1
;             @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueueCount(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Count
EndFunc   ;==>_ObjQueueCount

;==================================================================================================
; Name:      _ObjQueueToArray(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   0
;            Failure:  -1
;        @error:   1  Object does not exists
;                  3  Error while object interaction
;==================================================================================================
Func _ObjQueueToArray(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Local \$Array = \$ObjQueue.ToArray
If @error Then Return SetError(3, 0, -1)
Return \$Array
EndFunc   ;==>_ObjQueueToArray```
##### Share on other sites

Check this out:

You can use a "real" Queue instead.

```;==================================================================================================
; Name:      _ObjQueueCreate()
; Return:    Success:   Handle to the Queue-Object
;            Failure:  -1
;            @error:    1  Couldnt create Queue
;==================================================================================================
Func _ObjQueueCreate()
Local \$obj = ObjCreate("System.Collections.Queue")
If (Not IsObj(\$obj)) Then
Return SetError(1, 0, -1)
Else
Return \$obj
EndIf
EndFunc   ;==>_ObjQueueCreate

;==================================================================================================
; Parameter: \$ObjQueue - Handle to the Queue-Object
;            \$Value    - Value to add.
; Return:    Success   0
;            Failure:  -1
;        @error:   1  Object doesnt exist
;                  2  Value is empty
;                  3  Enqueue didnt work.
;==================================================================================================
Func _ObjQueueAdd(ByRef \$ObjQueue, \$VALUE = '')
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
If \$VALUE = '' Then Return SetError(2, 0, -1)
\$ObjQueue.Enqueue(\$VALUE)
If @error Then Return SetError(3, 0, -1)
Return 0

;==================================================================================================
; Name:      _ObjQueueSearch(\$ObjQueue, \$Value)
; Parameter: \$ObjQueue - Handle to the Queue-Object
;            \$Value    - Value to search
; Return:    Success   TRUE   Value exists
;                      FALSE  Value doesnt exist
;            Failure:  -1
;            @error:   1  Object doesnt exist
;                      2  Value is empty
;                      3  Error while object interaction
;==================================================================================================
Func _ObjQueueSearch(ByRef \$ObjQueue, \$VALUE = '')
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
If \$VALUE = '' Then Return SetError(2, 0, -1)
If \$ObjQueue.Contains(\$VALUE) Then
Return True
Else
Return False
EndIf
If @error Then Return SetError(3, 0, -1)
EndFunc   ;==>_ObjQueueSearch

;==================================================================================================
; Name:      _ObjQueueGetFirst(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   First value of the queue
;            Failure:  -1
;            @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueueGetFirst(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Peek
EndFunc   ;==>_ObjQueueGetFirst

;==================================================================================================
; Name:      _ObjQueuePopFirst(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   First Value of the Queue. It will also be deleted.
;            Failure:  -1
;            @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueuePopFirst(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Dequeue
EndFunc   ;==>_ObjQueuePopFirst

;==================================================================================================
; Name:      _ObjQueueCount(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   Amount of values in queue
;            Failure:  -1
;             @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueueCount(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Count
EndFunc   ;==>_ObjQueueCount

;==================================================================================================
; Name:      _ObjQueueToArray(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   0
;            Failure:  -1
;        @error:   1  Object does not exists
;                  3  Error while object interaction
;==================================================================================================
Func _ObjQueueToArray(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Local \$Array = \$ObjQueue.ToArray
If @error Then Return SetError(3, 0, -1)
Return \$Array
EndFunc   ;==>_ObjQueueToArray```

Wait... So AutoIt is compatible with C++ Programming?

##### Share on other sites

Wait... So AutoIt is compatible with C++ Programming?

Not the languages but the compilations from it, such as DLL's etc.
##### Share on other sites

Wait.. So then what is this?

I'm so confused lol

```;==================================================================================================
; Name:      _ObjQueueCreate()
; Return:    Success:   Handle to the Queue-Object
;            Failure:  -1
;            @error:    1  Couldnt create Queue
;==================================================================================================
Func _ObjQueueCreate()
Local \$obj = ObjCreate("System.Collections.Queue")
If (Not IsObj(\$obj)) Then
Return SetError(1, 0, -1)
Else
Return \$obj
EndIf
EndFunc   ;==>_ObjQueueCreate

;==================================================================================================
; Parameter: \$ObjQueue - Handle to the Queue-Object
;            \$Value    - Value to add.
; Return:    Success   0
;            Failure:  -1
;        @error:   1  Object doesnt exist
;                  2  Value is empty
;                  3  Enqueue didnt work.
;==================================================================================================
Func _ObjQueueAdd(ByRef \$ObjQueue, \$VALUE = '')
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
If \$VALUE = '' Then Return SetError(2, 0, -1)
\$ObjQueue.Enqueue(\$VALUE)
If @error Then Return SetError(3, 0, -1)
Return 0

;==================================================================================================
; Name:      _ObjQueueSearch(\$ObjQueue, \$Value)
; Parameter: \$ObjQueue - Handle to the Queue-Object
;            \$Value    - Value to search
; Return:    Success   TRUE   Value exists
;                      FALSE  Value doesnt exist
;            Failure:  -1
;            @error:   1  Object doesnt exist
;                      2  Value is empty
;                      3  Error while object interaction
;==================================================================================================
Func _ObjQueueSearch(ByRef \$ObjQueue, \$VALUE = '')
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
If \$VALUE = '' Then Return SetError(2, 0, -1)
If \$ObjQueue.Contains(\$VALUE) Then
Return True
Else
Return False
EndIf
If @error Then Return SetError(3, 0, -1)
EndFunc   ;==>_ObjQueueSearch

;==================================================================================================
; Name:      _ObjQueueGetFirst(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   First value of the queue
;            Failure:  -1
;            @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueueGetFirst(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Peek
EndFunc   ;==>_ObjQueueGetFirst

;==================================================================================================
; Name:      _ObjQueuePopFirst(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   First Value of the Queue. It will also be deleted.
;            Failure:  -1
;            @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueuePopFirst(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Dequeue
EndFunc   ;==>_ObjQueuePopFirst

;==================================================================================================
; Name:      _ObjQueueCount(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   Amount of values in queue
;            Failure:  -1
;             @error:   1  Object does not exists
;==================================================================================================
Func _ObjQueueCount(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Return \$ObjQueue.Count
EndFunc   ;==>_ObjQueueCount

;==================================================================================================
; Name:      _ObjQueueToArray(\$ObjQueue)
; Parameter: \$ObjQueue - Handle to the Queue-Object
; Return:    Success   0
;            Failure:  -1
;        @error:   1  Object does not exists
;                  3  Error while object interaction
;==================================================================================================
Func _ObjQueueToArray(ByRef \$ObjQueue)
If (Not IsObj(\$ObjQueue)) Then Return SetError(1, 0, -1)
Local \$Array = \$ObjQueue.ToArray
If @error Then Return SetError(3, 0, -1)
Return \$Array
EndFunc   ;==>_ObjQueueToArray```
##### Share on other sites

Wait.. So then what is this?

That script connects to a COM object. The script then creates user-defined-functions which call upon the objects native functions, allowing you to use AutoIt syntax a different files functions.

It's explained in the help file under ObjCreate().

##### Share on other sites

Do you think this is the best way to go at my original purpose?

I am actually checking a 1-100%(Usage Amount) Variable on 4 Different Network Monitors. I am trying to set it up so that it will alert me if any of the Network Monitors has a drop of more that 30% in less than 3 Seconds.

So I need to record the Variable from the network monitor as well as the time-stamp into an Array and have about 8 Records for each second(8 checks a second) and I would like to put them into a FILO structure on a Circular Buffer so that it continues indefinitely. <-- And do this for each of the 4 Network Monitors..

Edited by ericnail
##### Share on other sites

Maybe this will give you some ideas.

Uncommented cause I am very late for work

```#include <Array.au3>
\$num_comp = 4
\$buffer_sec = 3

Global \$usages[\$num_comp][\$buffer_sec + 1]
For \$i = 0 To UBound(\$usages) - 1
\$usages[\$i][0] = TimerInit()
For \$x = 1 To UBound(\$usages, 2) - 1
\$usages[\$i][\$x] = 0
Next
Next

While 1
For \$i = 0 To UBound(\$usages) - 1
If TimerDiff(\$usages[\$i][0]) >= 1000 Then
\$usages[\$i][0] = TimerInit()
\$use = _GetUsage(\$i) ;You can get the usage however you want.  As long as it returns a value between 0 and 100.
_CheckArray(\$i)
EndIf
Next
WEnd

Func _GetUsage(\$i)
Return Random(0, 100, 1)
EndFunc   ;==>_GetUsage

ConsoleWrite(\$iIndx & @TAB & \$iVal & @TAB)
Local \$alocal[UBound(\$usages, 2)]
For \$i = 1 To UBound(\$usages, 2) - 1
\$alocal[\$i - 1] = \$usages[\$iIndx][\$i]
Next
\$alocal[\$i - 1] = \$iVal

For \$i = 1 To UBound(\$usages, 2) - 1
\$usages[\$iIndx][\$i] = \$alocal[\$i]
ConsoleWrite(\$usages[\$iIndx][\$i] & @TAB)
Next

Func _CheckArray(\$iIndx)
If (\$usages[\$iIndx][2] - \$usages[\$iIndx][UBound(\$usages, 2) - 1]) >= 30 Then
ConsoleWrite ("30% Drop")
EndIf
ConsoleWrite (@CRLF)
EndFunc   ;==>_CheckArray```
##### Share on other sites

Only problem is that I need to have the queue work for 4 simultanious 1-100 figures.

##### Share on other sites

• 2 months later...

General Purpose Ring Buffer (Circular) FIFO queue

I'm developing a large AutoIt project that I call "HotRod". The goal is to take full advantage of the capabilities of programable keyboards like the Logic Controls LK1800 (http://www.logiccontrols.com/web/LK18.html), the Avant Stellar (http://www.cvtinc.com/products/keyboards/menu.htm) and programbale keypads like the PI X-keys's (http://www.piengineering.com/xkeys.php), and the Genovation ControlPad's (http://www.genovation.com/progkeypads.htm).

To allow for a large number of programbale keys, but to avoid conflicts with hotkeys already used by other programs, I program each key on the keyboard to send a sequence of hotkeys. For example, one key might send the sequence of three hotkeys "#1","#1","#1" (A "1" with the "Win" modifer key), while another key might send the sequence "#1","#1","#2", for seven possible combinations but using only two registered hotkeys.

The current version of HotRod actually uses four hotkeys ("#1","#2","#3","#4"), sent three at a time, which gives me 4^3 = 64 possible combinations. Plus a large number of additional sequences formed from these "base" values plus another modifier, like "+#1","+#1","+#1" (Shift-Win 1), and "^#1",^"#1",^"#1" (Ctrl-Win 1).

I opted not to use any of the keyboard "hook" methods to capture the incomming hotkeys, but instead built the project using the standard AutoIt "HotKeySet" function and the "@HotKeyPressed" macro. But, as I soon learned (the hard way), the user supplied "callback" function that you specify to "HotKeySet" must execute and return before the next hotkey arrives from the keyboard, or things get very confusing (incomming keys will be out of order or lost). Since in my case the keystrokes are being generated by a programbale keyboard, they come in much faster than any human could type, and I needed a way to quickly buffer the incomming keys for processing by an idle loop section of the code.

My solution was a Ring Buffer (Circular) FIFO queue. This is a standard algorithm (http://en.wikipedia.org/wiki/Circular_buffer) but I couldn't find any implimentaion of it that I liked in the AutoIt forums, or that was general enough to be used in many different situations. So ...

The following was "lifted" from the larger HotRod code, so there are a small number of references to utility functions (e.g. "ERR_Fatal()", "LOG_High()" ) and globals (e.g. "\$ERR_QUEOverrun") that aren't defined here, but I think the intention is pretty clear.

I welcome any suggestions for improving this code, or questions about HotRod and programable devices. (I will be posting the entire HotRod project here when it's finished).

```; ===========================================================================
;  Que Functions
; ===========================================================================

; QUE Control Array

Global Const \$QUE_CtrlSize = 4
Global Const \$QUE_NameIx = 0
Global Const \$QUE_SizeIx = 1
Global Const \$QUE_TailIx = 3

Func QUE_Init( \$QueName, ByRef \$QueCtrl, ByRef \$QueRing, \$QueSize )
Local Const \$Func = "QUE_Init"

ReDim \$QueCtrl[ \$QUE_CtrlSize ]
ReDim \$QueRing[ \$QueSize ]
\$QueCtrl[\$QUE_NameIx] = \$QueName
\$QueCtrl[\$QUE_SizeIx] = UBound( \$QueRing )
\$QueCtrl[\$QUE_TailIx] = 0

EndFunc

Func QUE_Put( ByRef \$QueCtrl, ByRef \$QueRing, \$QueValue )
Local Const \$Func = "QUE_Put"

If \$QueCtrl[\$QUE_HeadIx] = \$QueCtrl[\$QUE_TailIx] Then Return ERR_Fatal( \$Func, \$ERR_QUEOverrun, \$QueCtrl[\$QUE_NameIx] )

Return \$ERR_NoError

EndFunc

Func QUE_Get( ByRef \$QueCtrl, ByRef \$QueRing )
Local Const \$Func = "QUE_Get"

If QUE_IsEmpty( \$QueCtrl ) Then Return ERR_Fatal( \$Func, \$ERR_QUEUnderrun, \$QueCtrl[\$QUE_NameIx] )

Local \$QueValue = \$QueRing[\$QueCtrl[\$QUE_TailIx]]
\$QueCtrl[\$QUE_TailIx] = Mod( \$QueCtrl[\$QUE_TailIx] + 1, \$QueCtrl[\$QUE_SizeIx] )
Return \$QueValue

EndFunc

Func QUE_Cnt( ByRef \$QueCtrl )
Local Const \$Func = "QUE_Cnt"

Return Mod( \$QueCtrl[\$QUE_HeadIx] - \$QueCtrl[\$QUE_TailIx] + \$QueCtrl[\$QUE_SizeIx], \$QueCtrl[\$QUE_SizeIx] )

EndFunc

Func QUE_IsEmpty( ByRef \$QueCtrl )
Local Const \$Func = "QUE_IsEmpty"

Return ( \$QueCtrl[\$QUE_HeadIx] = \$QueCtrl[\$QUE_TailIx] )

EndFunc

Func QUE_IsNotEmpty( ByRef \$QueCtrl )
Local Const \$Func = "QUE_IsNotEmpty"

Return ( \$QueCtrl[\$QUE_HeadIx] <> \$QueCtrl[\$QUE_TailIx] )

EndFunc

Func QUE_2DS( ByRef \$QueCtrl, ByRef \$QueRing )
Local Const \$Func = "QUE_2DS"

Local \$Tail = \$QueCtrl[\$QUE_TailIx]
Local \$Size = \$QueCtrl[\$QUE_SizeIx]
Local \$DS = @CR

\$DS = \$DS & \$QueRing[\$Tail] & @CR
\$Tail = Mod( \$Tail + 1, \$Size )

WEnd

Return \$DS

EndFunc

Func QUE_2Array( ByRef \$QueCtrl, ByRef \$QueRing )
Local Const \$Func = "QUE_2Array"

Local \$Tail = \$QueCtrl[\$QUE_TailIx]
Local \$Size = \$QueCtrl[\$QUE_SizeIx]
Local \$DS[QUE_Cnt( \$QueCtrl ) + 1]
Local \$Ix = 0

\$Ix = \$Ix + 1
\$DS[\$Ix] = \$QueRing[\$Tail]
\$Tail = Mod( \$Tail + 1, \$Size )

WEnd

Return \$DS

EndFunc

; ===========================================================================
;  Example Usage
; ===========================================================================

; ---------------------------------------------------------------------------
; HotKey Sequence Que
; ---------------------------------------------------------------------------

Global \$HKS_QueCtrl[1]          ; Que Control
Global \$HKS_QueRing[1]          ; Que Ring

; Que init

Func HKS_QueInit()
Local Const \$Func = "HKS_QueInit"

QUE_Init( "\$HKS_Que", \$HKS_QueCtrl, \$HKS_QueRing, 8 )
If ERR_Any() Then Return

EndFunc

; Que is not empty?

Func HKS_QueIsNotEmpty()
Local Const \$Func = "HKS_QueIsNotEmpty"

Return QUE_IsNotEmpty( \$HKS_QueCtrl )

EndFunc

; ---------------------------------------------------------------------------
; Callback for registered HotKeys (Event Driven)
; ---------------------------------------------------------------------------
Func HKS_In()
Local Const \$Func = "HKS_In"

; Que this HotKey

QUE_Put( \$HKS_QueCtrl, \$HKS_QueRing, @HotKeyPressed )
If ERR_Any() Then ERR_Catch()

Return

EndFunc

; ---------------------------------------------------------------------------
;  Process any HotKeys on the que (Idle Loop)
; ---------------------------------------------------------------------------
Func HKS_QueDo()
Local Const \$Func = "HKS_QueDo"

; Pop the que

Local \$HotKey = QUE_Get( \$HKS_QueCtrl, \$HKS_QueRing )
If ERR_Any() Then Return
LOG_High( \$Func, "HotKey = '" & \$HotKey & "'." )

EndFunc

; ---------------------------------------------------------------------------
; APP_Idle Object
; ---------------------------------------------------------------------------
Global \$APP_IdleSleep = 250

Func APP_Idle()
Local Const \$Func = "APP_Idle"

While True

While HKS_QueIsNotEmpty()
HKS_QueDo()
ERR_Catch()
WEnd

Sleep( \$APP_IdleSleep )

WEnd

EndFunc```

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...