ericnail Posted April 3, 2010 Share Posted April 3, 2010 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. Could someone please help me? Link to comment Share on other sites More sharing options...
BrettF Posted April 3, 2010 Share Posted April 3, 2010 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
martin Posted April 3, 2010 Share Posted April 3, 2010 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. Could someone please help me? 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> Dim $fifo1[100];start with 100 elements but we can grow as needed 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. Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Author Share Posted April 3, 2010 (edited) 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,BrettYeah, 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..~EricP.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 April 3, 2010 by ericnail Link to comment Share on other sites More sharing options...
SEuBo Posted April 3, 2010 Share Posted April 3, 2010 Check this out: You can use a "real" Queue instead. expandcollapse popup;================================================================================================== ; 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 ;================================================================================================== ; Name: _ObjQueueAdd($ObjQueue, $Value) ; 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 EndFunc ;==>_ObjQueueAdd ;================================================================================================== ; 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 AutoIt Examples/UDF's:Generate Function at Runtime using IRunningObjectTable / AutoItObjectVery Simple Inter-Process Communication (using AutoItObject Pure AutoIt) Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Author Share Posted April 3, 2010 Check this out: You can use a "real" Queue instead. expandcollapse popup;================================================================================================== ; 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 ;================================================================================================== ; Name: _ObjQueueAdd($ObjQueue, $Value) ; 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 EndFunc ;==>_ObjQueueAdd ;================================================================================================== ; 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? Link to comment Share on other sites More sharing options...
James Posted April 3, 2010 Share Posted April 3, 2010 Wait... So AutoIt is compatible with C++ Programming?Not the languages but the compilations from it, such as DLL's etc. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Author Share Posted April 3, 2010 Wait.. So then what is this? I'm so confused lol expandcollapse popup;================================================================================================== ; 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 ;================================================================================================== ; Name: _ObjQueueAdd($ObjQueue, $Value) ; 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 EndFunc ;==>_ObjQueueAdd ;================================================================================================== ; 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 Link to comment Share on other sites More sharing options...
James Posted April 3, 2010 Share Posted April 3, 2010 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(). Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
ericnail Posted April 3, 2010 Author Share Posted April 3, 2010 (edited) 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 April 3, 2010 by ericnail Link to comment Share on other sites More sharing options...
BrettF Posted April 3, 2010 Share Posted April 3, 2010 Maybe this will give you some ideas. Uncommented cause I am very late for work expandcollapse popup#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. _AddToArray($i, $use) _CheckArray($i) EndIf Next WEnd Func _GetUsage($i) Return Random(0, 100, 1) EndFunc ;==>_GetUsage Func _AddToArray($iIndx, $iVal) 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 EndFunc ;==>_AddToArray Func _CheckArray($iIndx) If ($usages[$iIndx][2] - $usages[$iIndx][UBound($usages, 2) - 1]) >= 30 Then ConsoleWrite ("30% Drop") EndIf ConsoleWrite (@CRLF) EndFunc ;==>_CheckArray Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
ericnail Posted April 4, 2010 Author Share Posted April 4, 2010 Only problem is that I need to have the queue work for 4 simultanious 1-100 figures. Link to comment Share on other sites More sharing options...
AGlassman Posted June 26, 2010 Share Posted June 26, 2010 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). expandcollapse popup; =========================================================================== ; Que Functions ; =========================================================================== ; QUE Control Array Global Const $QUE_CtrlSize = 4 Global Const $QUE_NameIx = 0 Global Const $QUE_SizeIx = 1 Global Const $QUE_HeadIx = 2 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_HeadIx] = 0 $QueCtrl[$QUE_TailIx] = 0 EndFunc Func QUE_Put( ByRef $QueCtrl, ByRef $QueRing, $QueValue ) Local Const $Func = "QUE_Put" $QueRing[$QueCtrl[$QUE_HeadIx]] = $QueValue $QueCtrl[$QUE_HeadIx] = Mod( $QueCtrl[$QUE_HeadIx] + 1, $QueCtrl[$QUE_SizeIx] ) 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 $Head = $QueCtrl[$QUE_HeadIx] Local $Tail = $QueCtrl[$QUE_TailIx] Local $Size = $QueCtrl[$QUE_SizeIx] Local $DS = @CR While $Tail <> $Head $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 $Head = $QueCtrl[$QUE_HeadIx] Local $Tail = $QueCtrl[$QUE_TailIx] Local $Size = $QueCtrl[$QUE_SizeIx] Local $DS[QUE_Cnt( $QueCtrl ) + 1] Local $Ix = 0 While $Tail <> $Head $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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now