VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "clsInputQueue" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit ' [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ' [[ [[ ' [[ Input Queue [[ ' [[ [[ ' [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ 'Input Queue class - Used to queue several input actions, like keystrokes, mouseclicks 'with optional delays '>> Must create a tmrInputTimer VB Timer control and put it on a form called frmTimer 'Note: Alt tabbed inputs doesnt seem to work the 1st time they are used. However, they work 'the next times. Sounds like the 1st sendmessage is skipped, and others are processed as intended. 'Does same thing for alt tabbed key push. No idea why. Private Enum eInputTypes INPUT_TYPE_LEFTCLICK INPUT_TYPE_KEYPUSH INPUT_TYPE_MOUSEDRAG INPUT_TYPE_DELAY INPUT_TYPE_WRITE_TO_CHATBAR INPUT_TYPE_WRITE_TO_CONSOLE NUM_INPUT_TYPES End Enum 'Timer ticks frequency Private Const INPUT_TIMER_INTERVAL = 20 'msec 'delays - time to wait after input is processed Private Const KEYPUSH_DELAY = 0 Private Const MOUSECLICK_DELAY = 0 Private Const MOUSEDRAG_DELAY = 0 Private Const WRITE_TO_CHATBAR_DELAY = 0 Private Const WRITE_TO_CONSOLE_DELAY = 0 'Private class members Private WithEvents m_InputTimer As Timer 'reference to VB timer control Attribute m_InputTimer.VB_VarHelpID = -1 Private m_InputQueue As Collection 'the list of inputs to process, the one at top being the next one to be processed Private m_Time As Double 'internal timer Private m_Delay As Double 'when we will be able to process input again Private Sub Class_Initialize() On Error GoTo Error_Handler MyDebug " -- InputQueue Object Initializing -- " Set m_InputQueue = New Collection Set m_InputTimer = frmTimer.tmrInputQueue m_InputTimer.Enabled = True m_InputTimer.Interval = INPUT_TIMER_INTERVAL m_Time = 0 m_Delay = 0 Fin: Exit Sub Error_Handler: PrintErrorMessage "clsInputQueue.Class_Initialize : Error #" & Err.Number & " (line: " & Erl & ") has been generated by " & Err.Source & " : " & Err.Description Resume Fin End Sub Private Sub Class_Terminate() Set m_InputQueue = Nothing Set m_InputTimer = Nothing End Sub '============================================================================ ' AddInputToQueue '--------------------------------------------------------------------------- ' Adds an InputItem at the end of the InputQueue '============================================================================ Private Sub AddInputToQueue(objInputItem As clsInputQueueItem) On Error GoTo Error_Handler Call m_InputQueue.Add(objInputItem) Fin: Exit Sub Error_Handler: PrintErrorMessage "AddInputToQueue : Error #" & Err.Number & " (line: " & Erl & ") has been generated by " & Err.Source & " : " & Err.Description Resume Fin End Sub '============================================================================ ' OnInputTimerTick '--------------------------------------------------------------------------- ' Must be called by the input timer control on every tick ' Will check if the next input can be processed '============================================================================ Public Sub OnInputTimerTick() If m_InputQueue.Count >= 1 Then 'MyDebug "OnInputTimerTick - m_Time = " & m_Time If m_InputTimer.Interval <= 0 Then PrintErrorMessage "OnInputTimerTick : TimerInterval not set !" Exit Sub End If If m_Delay <= m_Time Then 'delay timer expired, process next input Call ProcessNextInput End If 'Update internal timer m_Time = m_Time + CDbl(m_InputTimer.Interval / 1000) 'timer in seconds Else m_Time = 0 m_Delay = 0 End If End Sub '============================================================================ ' Clear '--------------------------------------------------------------------------- ' Clear the Input Queue '============================================================================ Public Sub Clear() Dim i As Integer For i = 1 To m_InputQueue.Count Call m_InputQueue.Remove(1) Next i End Sub '============================================================================ ' ProcessNextInput '--------------------------------------------------------------------------- ' Process the next input item (the first input item in the queue) '============================================================================ Private Sub ProcessNextInput() On Error GoTo Error_Handler Dim CurInput As clsInputQueueItem If m_InputQueue.Count < 1 Then MsgBox "WARNING: ProcessNextInput - m_InputQueue.Count < 1" Exit Sub End If 'Collection.Item has base index = 1 Set CurInput = m_InputQueue.Item(1) 'TODO: input handling here MyDebug "Processing Input : " & GetInputString(CurInput) Select Case CurInput.InputType Case INPUT_TYPE_LEFTCLICK Call g_Core.MouseClick(CurInput.Pos.x, CurInput.Pos.y) 'NOTE : this won't send keys to the AC Console ! Use the Input.WriteToConsole instead Case INPUT_TYPE_KEYPUSH Call g_Core.SendKey(CurInput.KeyCode) Case INPUT_TYPE_MOUSEDRAG 'TODO Case INPUT_TYPE_WRITE_TO_CHATBAR Call g_Core.SendTextToConsole(CurInput.Text, True) Case INPUT_TYPE_WRITE_TO_CONSOLE PrintMessage CurInput.Text End Select 'Check if we need to add a litlle delay after processing this event If CurInput.Delay > 0 Then m_Delay = m_Time + CurInput.Delay / 1000 '.Delay is in msec End If 'Remove this input item from top of the queue Call m_InputQueue.Remove(1) Fin: Exit Sub Error_Handler: PrintErrorMessage "ProcessNextInput : Error #" & Err.Number & " (line: " & Erl & ") has been generated by " & Err.Source & " : " & Err.Description Resume Fin End Sub '============================================================================ ' GetInputString '--------------------------------------------------------------------------- ' For debug purpose mostly, just returns a string with ' info about the InputItem passed as parameter '============================================================================ Private Function GetInputString(InputItem As clsInputQueueItem) As String Select Case InputItem.InputType Case INPUT_TYPE_LEFTCLICK GetInputString = "MouseClick @ (" & InputItem.Pos.x & ", " & InputItem.Pos.y & ")" Case INPUT_TYPE_KEYPUSH GetInputString = "KeyPush : " & Chr(InputItem.KeyCode) & " [Asc = " & InputItem.KeyCode & "]" Case INPUT_TYPE_DELAY GetInputString = "Delay : " & InputItem.Delay & " msec" Case INPUT_TYPE_WRITE_TO_CHATBAR GetInputString = "Write to Chatbar : " & InputItem.Text Case INPUT_TYPE_WRITE_TO_CONSOLE GetInputString = "Write to Console : " & InputItem.Text Case INPUT_TYPE_MOUSEDRAG GetInputString = "MouseDrag from (" & InputItem.Pos.x & ", " & InputItem.Pos.y & ") to (" & InputItem.Pos2.x & ", " & InputItem.Pos2.y & ")" Case Else GetInputString = "Unkown InputType " & InputItem.InputType End Select End Function '============================================================================ ' DisplayInputQueue '--------------------------------------------------------------------------- ' For debug only '============================================================================ Public Sub DisplayInputQueue() Dim InputItem As clsInputQueueItem Dim Counter As Integer Dim strDisplay As String Counter = 1 MyDebug "====== Displaying InputQueue ======" MyDebug " TimerTick Interval : " & m_InputTimer.Interval & " msec" For Each InputItem In m_InputQueue MyDebug "Input Item #" & Counter & " : " & GetInputString(InputItem) Counter = Counter + 1 Next InputItem End Sub '============================================================================ ' m_InputTimer_Timer '--------------------------------------------------------------------------- ' Timer tick '============================================================================ Private Sub m_InputTimer_Timer() Call OnInputTimerTick End Sub '============================================================================ ' MouseClick (x, y [, Delay]) '--------------------------------------------------------------------------- ' Adds a MouseClick input item to the InputQueue ' When processed, it will make the AC client click at screen position (x,y) '============================================================================ Public Sub MouseClick(x As Integer, y As Integer, Optional Delay As Integer = MOUSECLICK_DELAY) Dim NewInput As New clsInputQueueItem NewInput.InputType = INPUT_TYPE_LEFTCLICK NewInput.Pos.x = x NewInput.Pos.y = y NewInput.Delay = Delay Call AddInputToQueue(NewInput) 'Clean up Set NewInput = Nothing End Sub '============================================================================ ' PushKey (lKeyCode [, Delay]) '--------------------------------------------------------------------------- ' Adds a Key Push input item to the InputQueue ' When processed, it will make the AC client push the desired key ' ' IMPORTANT NOTE : this won't send keys to the AC Console ! Use the Input.WriteToConsole instead '============================================================================ Public Sub PushKey(lKeyCode As Long, Optional Delay As Integer = KEYPUSH_DELAY) Dim NewInput As New clsInputQueueItem NewInput.InputType = INPUT_TYPE_KEYPUSH NewInput.KeyCode = lKeyCode NewInput.Delay = Delay Call AddInputToQueue(NewInput) 'Clean up Set NewInput = Nothing End Sub '============================================================================ ' MouseDrag (x1, y1, x2, y2 [, Delay]) '--------------------------------------------------------------------------- ' Adds a Mouse Dragging input item to the InputQueue ' When processed, it will make the AC client click at screen position (x1,y1), ' hold the left mouse button, and drag the cursor to screen position (x2,y2) '============================================================================ Public Sub MouseDrag(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, Optional Delay As Integer = MOUSEDRAG_DELAY) Dim NewInput As New clsInputQueueItem NewInput.InputType = INPUT_TYPE_MOUSEDRAG NewInput.Pos.x = x1 NewInput.Pos.y = y1 NewInput.Pos2.x = x2 NewInput.Pos2.y = y2 NewInput.Delay = Delay Call AddInputToQueue(NewInput) 'Clean up Set NewInput = Nothing End Sub '============================================================================ ' Delay (TimeInMsec) '--------------------------------------------------------------------------- ' Adds a Delay to the processing of the next input item of the inputqueue ' Value must be in msec '============================================================================ Public Sub Delay(TimeInMsec As Double) Dim NewInput As New clsInputQueueItem NewInput.InputType = INPUT_TYPE_DELAY NewInput.Delay = TimeInMsec Call AddInputToQueue(NewInput) 'Clean up Set NewInput = Nothing End Sub '============================================================================ ' WriteToChatbar (Text [, Delay]) '--------------------------------------------------------------------------- ' Adds a WriteToChatbar input item to the InputQueue ' When processed, it will hit ENTER, write the Text to the AC chat bar, and ' hit ENTER again to send it. ' ' This can be used to send commands or delayed chat messages '============================================================================ Public Sub WriteToChatbar(Text As String, Optional Delay As Integer = WRITE_TO_CHATBAR_DELAY) Dim NewInput As New clsInputQueueItem NewInput.InputType = INPUT_TYPE_WRITE_TO_CHATBAR NewInput.Text = Text NewInput.Delay = Delay Call AddInputToQueue(NewInput) 'Clean up Set NewInput = Nothing End Sub '============================================================================ ' WriteToConsole (Text [, Delay]) '--------------------------------------------------------------------------- ' Adds a WriteToConsole input item to the InputQueue ' When processed, it will print the Text to the AC console '============================================================================ Public Sub WriteToConsole(Text As String, Optional Delay As Integer = WRITE_TO_CONSOLE_DELAY) Dim NewInput As New clsInputQueueItem NewInput.InputType = INPUT_TYPE_WRITE_TO_CONSOLE NewInput.Text = Text NewInput.Delay = Delay Call AddInputToQueue(NewInput) 'Clean up Set NewInput = Nothing End Sub