Est-il possible d'accélérer une partie du programe?
banania72000
Messages postés3Date d'inscriptionsamedi 7 mars 2009StatutMembreDernière intervention21 juillet 2010
-
20 juil. 2010 à 01:16
banania72000
Messages postés3Date d'inscriptionsamedi 7 mars 2009StatutMembreDernière intervention21 juillet 2010
-
21 juil. 2010 à 13:12
Voila je débute dans tous se qui touche a virual basic et je voulais savoir si il était possible d'accélérer une action et si cela était possible grâce a quel code ?
Je m'explique mon programme permet d'enregistré les mouvement de la souris et du clavier et les envoie dans une scriptbox pour après lorsque l'on appuie sur le bouton lancer le programme répète l'action une fois ou alors plusieurs fois si l'on appui sur le bouton boucle.Pour l'instant tous cela fonctionne très bien mais moi je voudrait que la répétition du mouvement de la souris soit accélérer cela est-il possible? Voila ce que je vous demande.En espérant avoir été assez claire.
banania72000
Messages postés3Date d'inscriptionsamedi 7 mars 2009StatutMembreDernière intervention21 juillet 2010 20 juil. 2010 à 12:55
Public Class FrmMain
#Region " API Souris "
Private Declare Sub Mouse_Event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Private Sub DoMouseEvent(ByVal Button As Integer, Optional ByVal ExtraInfo As Integer = 0)
Mouse_Event(Button, 0, 0, ExtraInfo, 1)
End Sub
#End Region
#Region " API Clavier "
Private Declare Sub Keybd_Event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UIntPtr)
Private Sub DoKeyEvent(ByVal KeyCode As Integer, ByVal Up As Boolean)
Keybd_Event(KeyCode, &H45, IIf(Up, KEYEVENTF_KEYUP Or KEYEVENTF_EXTENDEDKEY, KEYEVENTF_EXTENDEDKEY), 0)
End Sub
#End Region
#Region " Déclarations "
Private m_ToMake As String = ""
Private m_LastAction As Long = 0
Private m_Listen As Boolean = False
Private m_IsWorking As Boolean = False
Private Sub Wait(ByVal Time As Long)
Dim Quota As Long = Time + Environment.TickCount
While Quota > Environment.TickCount
Threading.Thread.Sleep(1)
Application.DoEvents()
End While
End Sub
#End Region
#Region " Ajout d'events "
Private Sub AddWaitEvent()
If Not m_Listen Then Exit Sub
If m_LastAction <> 0 Then
Dim TimeWait As Long = Environment.TickCount - m_LastAction
If TimeWait > 0 Then
m_ToMake &= "W," & TimeWait & vbCrLf
End If
End If
m_LastAction = Environment.TickCount
End Sub
Private Sub AddMouseEvent(ByVal X As Integer, ByVal Y As Integer)
If Not m_Listen Then Exit Sub
AddWaitEvent()
m_ToMake &= "M," & X & "," & Y & vbCrLf
End Sub
Private Sub AddClickEvent(ByVal Up As Boolean, ByVal Button As Windows.Forms.MouseButtons)
If Not m_Listen Then Exit Sub
AddWaitEvent()
Select Case Button
Case Windows.Forms.MouseButtons.Left
If Up Then
m_ToMake &= "C," & MOUSEEVENTF_LEFTUP & vbCrLf
Else
m_ToMake &= "C," & MOUSEEVENTF_LEFTDOWN & vbCrLf
End If
Case Windows.Forms.MouseButtons.Middle
If Up Then
m_ToMake &= "C," & MOUSEEVENTF_MIDDLEUP & vbCrLf
Else
m_ToMake &= "C," & MOUSEEVENTF_MIDDLEDOWN & vbCrLf
End If
Case Windows.Forms.MouseButtons.Right
If Up Then
m_ToMake &= "C," & MOUSEEVENTF_RIGHTUP & vbCrLf
Else
m_ToMake &= "C," & MOUSEEVENTF_RIGHTDOWN & vbCrLf
End If
End Select
End Sub
Private Sub AddKeyEvent(ByVal KeyNumber As Integer, ByVal Up As Boolean)
Private Sub MouseMoved(ByVal sender As System.Object, ByVal e As Windows.Forms.MouseEventArgs)
Dim Maximum As Rectangle = Screen.PrimaryScreen.Bounds
If e.X >= Maximum.Left AndAlso e.Y >= Maximum.Top AndAlso _
e.X <= Maximum.Right AndAlso e.Y <= Maximum.Bottom Then
AddMouseEvent(e.X, e.Y)
End If
End Sub
Private Sub MouseUpped(ByVal sender As System.Object, ByVal e As Windows.Forms.MouseEventArgs)
AddClickEvent(True, e.Button)
End Sub
Private Sub MouseDowned(ByVal sender As System.Object, ByVal e As Windows.Forms.MouseEventArgs)
AddClickEvent(False, e.Button)
End Sub
Private Sub MouseWheeled(ByVal sender As System.Object, ByVal e As Windows.Forms.MouseEventArgs)
Private Sub KeyPressed(ByVal sender As System.Object, ByVal e As Windows.Forms.KeyEventArgs)
Select Case e.KeyCode
Case Keys.F6
ToggleApp()
Case Keys.F7
StartWorking(1)
Case Keys.F8
StartWorking(100000)
Case Keys.F9
StartWorking(1)
Case Keys.F10
StartWorking(1)
Case Keys.F11
StartWorking(1)
Case Else
AddKeyEvent(e.KeyCode, False)
End Select
End Sub
Private Sub KeyUpped(ByVal sender As System.Object, ByVal e As Windows.Forms.KeyEventArgs)
Select Case e.KeyCode
Case Keys.F6
Case Keys.F7
Case Keys.F8
Case Keys.F9
Case Keys.F10
Case Keys.F11
Case Else
AddKeyEvent(e.KeyCode, True)
If m_Listen Then
StopApp()
LearnButton.Text = "Learn (F6)"
ScriptBox.Text = m_ToMake
Else
StartApp()
LearnButton.Text = "Stop (F6)"
ScriptBox.Text = "En cours d'enregistrement..."
End If
End Sub
Private Sub conexion()
If m_Listen Then
StopApp()
Button2.Text = "connexion des comptes (F11)"
ScriptBox.Text = ""
Else
StartApp()
Button2.Text = "Stop (F6)"
ScriptBox.Text = "En cours de connexion..."
End If
End Sub
#End Region
#Region " Répétition "
Private Sub StartRepeat(ByVal Number As Integer)
m_IsWorking = True
For i As Integer = 1 To Number
If Not m_IsWorking Then Exit For
For Each Line As String In ScriptBox.Lines
If Not m_IsWorking Then Exit For
If Line <> "" Then
Dim Data() As String = Line.Split(",")
Execute(Data)
End If
Next
Next
StartWorking(0)
End Sub
Private Sub StartWorking(ByVal Number As Integer)
If Not m_IsWorking Then
RepeatButton.Text = "Stop (F7)"
RepeatButton2.Text = "Stop (F8)"
StartRepeat(Number)
Else
m_IsWorking = False
RepeatButton.Text = "Launch (F7)"
RepeatButton2.Text = "Repeat (F8)"
End If
Catch ex As Exception
Debug.Print(ex.ToString)
End Try
End Sub
#End Region
#Region " Formulaire "
Private Sub LearnButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LearnButton.Click
ToggleApp()
End Sub
Private Sub RepeatButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RepeatButton.Click
StartWorking(1)
End Sub
Private Sub RepeatButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RepeatButton2.Click
StartWorking(100000)
End Sub
Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Gma.UserActivityMonitor.HookManager.KeyDown, AddressOf KeyPressed
AddHandler Gma.UserActivityMonitor.HookManager.KeyUp, AddressOf KeyUpped
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
StartWorking(1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
conexion()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
StartWorking(1)
End Sub
#End Region
Private Sub ScriptBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScriptBox.TextChanged